Beispiel #1
0
        public void RemoveTask(ChargingTask task, bool bLock = true)
        {
            if (bLock == true)
            {
                if (this.m_lock.TryEnterWriteLock(m_nLockTimeout) == false)
                {
                    throw new LockException("锁定尝试中超时");
                }
            }
            try
            {
                this._tasks.Remove(task);
            }
            finally
            {
                if (bLock == true)
                {
                    this.m_lock.ExitWriteLock();
                }
            }

            // 兑现显示
            this.Container.DisplayTask("remove", task);
            this.Container.SetColorList();
        }
Beispiel #2
0
        // 加入一个任务到列表中
        public void AddTask(ChargingTask task)
        {
            task.Color = "black";                            // 表示等待处理
            if (this.m_lock.TryEnterWriteLock(500) == false) // m_nLockTimeout
            {
                throw new LockException("锁定尝试中超时");
            }
            try
            {
                this._tasks.Add(task);
            }
            finally
            {
                this.m_lock.ExitWriteLock();
            }

            // 触发任务开始执行
            this.Activate();

            // 兑现显示
            this.Container.DisplayTask("add", task);
            this.Container.SetColorList();
        }
Beispiel #3
0
        // 响应一个任务状态的改变
        public void OnTaskStateChanged(string strAction, ChargingTask task)
        {
            if (this.PatronSummaries == null)
            {
                return;
            }

            foreach (PatronSummary summary in this.PatronSummaries)
            {
                if (summary.Tasks.IndexOf(task) != -1)
                {
                    if (strAction == "remove")
                    {
                        summary.RemoveTask(task);
                    }
                    else if (strAction == "refresh" ||
                             strAction == "refresh_and_visible")
                    {
                        summary.RefreshColorList();
                    }
                    return;
                }
            }
        }
Beispiel #4
0
 DpRow FindTaskLine(ChargingTask task)
 {
     foreach (DpRow line in this.dpTable_tasks.Rows)
     {
         if (line.Tag == task)
             return line;
     }
     return null;
 }
Beispiel #5
0
        // parameters:
        //      strTaskID   任务 ID,用于管理和查询任务状态
        //      strParameters   附加的参数。可用于描述测试要求
        void _doAction(FuncState func,
            string strText,
            string strTaskID,
            string strParameters)
        {
            if (string.IsNullOrEmpty(strText) == true)
            {
                MessageBox.Show(this, "请输入适当的条码号");
                this.textBox_input.SelectAll();
                this.textBox_input.Focus();
                return;
            }

            // 如果中间(温和)停止过,则需要重新启动线程
            if (this._taskList.Stopped == true)
                this._taskList.BeginThread();

#if NO
            if (this._summaryList.Stopped == true)
                this._summaryList.BeginThread();
#endif
            // m_webExternalHost_readerInfo.StopPrevious();

            if ((this.UseIsbnBorrow == true && IsISBN(ref strText) == true)
                || strText.ToLower() == "?b")
            {
                string strItemBarcode = "";
                string strError = "";
                // return:
                //      -1  error
                //      0   放弃
                //      1   成功
                int nRet = SelectOneItem(func,
                    strText.ToLower() == "?b" ? "" : strText,
                    out strItemBarcode,
                    out strError);
                if (nRet == -1)
                {
                    MessageBox.Show(this, "选择册记录的过程中出错: " + strError);
                    this.textBox_input.SelectAll();
                    this.textBox_input.Focus();
                    return;
                }
                if (nRet == 0)
                {
                    MessageBox.Show(this, "已取消选择册记录。注意操作并未执行");
                    this.textBox_input.SelectAll();
                    this.textBox_input.Focus();
                    return;
                }

                strText = strItemBarcode;
            }

            // 检查条码号,如果是读者证条码号,则 func = LoadPatronInfo
            if (this.NeedVerifyBarcode == true)
            {
                if (StringUtil.IsIdcardNumber(strText) == true
                    || IsName(strText) == true)
                {
                    WillLoadReaderInfo = true;
                }
                else if (func == dp2Circulation.FuncState.Read
                    && string.IsNullOrEmpty(strText) == false
                    && strText.ToLower().StartsWith("@bibliorecpath:") == true)
                {
                    if (this.WillLoadReaderInfo == true)
                    {
                        // TODO: 语音提示
                        MessageBox.Show(this, "这里需要输入 证 条码号,而您输入的 '" + strText + "' 是一个 册 条码号。\r\n\r\n请重新输入");
                        this.textBox_input.SelectAll();
                        return;
                    }
                }
                else
                {
                    string strError = "";
                    // 形式校验条码号
                    // return:
                    //      -2  服务器没有配置校验方法,无法校验
                    //      -1  error
                    //      0   不是合法的条码号
                    //      1   是合法的读者证条码号
                    //      2   是合法的册条码号
                    int nRet = VerifyBarcode(
                        this.MainForm.FocusLibraryCode,  // this.Channel.LibraryCodeList,
                        strText,
                        out strError);
                    if (nRet == -2)
                    {
                        MessageBox.Show(this, "服务器没有配置条码号验证脚本,无法使用验证条码号功能。请在前端参数配置对话框的“快捷出纳”属性页中清除“校验输入的条码号”事项");
                        this.textBox_input.SelectAll();
                        this.textBox_input.Focus();
                        return;
                    }
                    if (nRet == -1)
                    {
                        // TODO: 语音提示
                        // TODO: 红色对话框
                        MessageBox.Show(this, strError);
                        this.textBox_input.SelectAll();
                        this.textBox_input.Focus();
                        return;
                    }
                    if (nRet == 0)
                    {
                        // TODO: 语音提示
                        // TODO: 红色对话框
                        MessageBox.Show(this, "'" + strText + "' 不是合法的条码号: " + strError);
                        this.textBox_input.SelectAll();
                        this.textBox_input.Focus();
                        return;
                    }
                    // 有可能 验证条码号的时候因为 EnableControls 丢失了焦点
                    this.textBox_input.Focus();

                    if (nRet == 1)
                        WillLoadReaderInfo = true;
                    else
                    {
                        Debug.Assert(nRet == 2, "");
                        if (this.WillLoadReaderInfo == true)
                        {
                            // TODO: 语音提示
                            MessageBox.Show(this, "这里需要输入 证 条码号,而您输入的 '" + strText + "' 是一个 册 条码号。\r\n\r\n请重新输入");
                            this.textBox_input.SelectAll();
                            return;
                        }
                    }
                }
            }

            if (WillLoadReaderInfo == true)
            {
                func = FuncState.LoadPatronInfo;
                // _bLoadReaderInfo = false;
            }

            ChargingTask task = new ChargingTask();
            task.ID = strTaskID;
            if (func == FuncState.LoadPatronInfo)
            {
                task.ReaderBarcode = strText;
                task.Action = "load_reader_info";
            }
            else if (func == dp2Circulation.FuncState.Borrow)
            {
                task.ReaderBarcode = this._taskList.CurrentReaderBarcode;
                task.ItemBarcode = strText;
                task.Action = "borrow";
            }
            else if (func == dp2Circulation.FuncState.ContinueBorrow)
            {
                if (string.IsNullOrEmpty(this._taskList.CurrentReaderBarcode) == true)
                {
                    WillLoadReaderInfo = true;
                    // 提示请输入读者证条码号
                    // TODO: 这里直接出现对话框搜集读者证条码号
                    MessageBox.Show(this, "请先输入读者证条码号,然后再输入册条码号");
                    this.textBox_input.SelectAll();
                    return;
                }
                task.ReaderBarcode = this._taskList.CurrentReaderBarcode;
                task.ItemBarcode = strText;
                task.Action = "borrow";
            }
            else if (func == dp2Circulation.FuncState.Renew)
            {
                // task.ReaderBarcode = "";
                task.ItemBarcode = strText;
                task.Action = "renew";
            }
            else if (func == dp2Circulation.FuncState.VerifyRenew)
            {
                task.ReaderBarcode = this._taskList.CurrentReaderBarcode;
                task.ItemBarcode = strText;
                task.Action = "verify_renew";
            }
            else if (func == dp2Circulation.FuncState.Return)
            {
                task.ItemBarcode = strText;
                task.Action = "return";
                task.Parameters = strParameters;
            }
            else if (func == dp2Circulation.FuncState.InventoryBook)
            {
                task.ReaderBarcode = this.BatchNo;
                task.ItemBarcode = strText;
                task.Action = "inventory";
            }
            else if (func == dp2Circulation.FuncState.VerifyReturn)
            {
                if (string.IsNullOrEmpty(this._taskList.CurrentReaderBarcode) == true)
                {
                    WillLoadReaderInfo = true;
                    // 提示请输入读者证条码号
                    // TODO: 这里直接出现对话框搜集读者证条码号
                    MessageBox.Show(this, "请先输入读者证条码号,然后再输入册条码号");
                    this.textBox_input.SelectAll();
                    return;
                }
                task.ReaderBarcode = this._taskList.CurrentReaderBarcode;
                task.ItemBarcode = strText;
                task.Action = "verify_return";
                task.Parameters = strParameters;
            }
            else if (func == dp2Circulation.FuncState.Lost)
            {
                task.ItemBarcode = strText;
                task.Action = "lost";
                task.Parameters = strParameters;
            }
            else if (func == dp2Circulation.FuncState.VerifyLost)
            {
                if (string.IsNullOrEmpty(this._taskList.CurrentReaderBarcode) == true)
                {
                    WillLoadReaderInfo = true;
                    // 提示请输入读者证条码号
                    MessageBox.Show(this, "请先输入读者证条码号,然后再输入册条码号");
                    this.textBox_input.SelectAll();
                    return;
                }
                task.ReaderBarcode = this._taskList.CurrentReaderBarcode;
                task.ItemBarcode = strText;
                task.Action = "verify_lost";
                task.Parameters = strParameters;
            }
            else if (func == dp2Circulation.FuncState.Read)
            {
                if (string.IsNullOrEmpty(this._taskList.CurrentReaderBarcode) == true)
                {
                    WillLoadReaderInfo = true;
                    // 提示请输入读者证条码号
                    // TODO: 这里直接出现对话框搜集读者证条码号
                    MessageBox.Show(this, "请先输入读者证条码号,然后再输入册条码号");
                    this.textBox_input.SelectAll();
                    return;
                }
                task.ReaderBarcode = this._taskList.CurrentReaderBarcode;
                task.ItemBarcode = strText;
                task.Action = "read";
            }

            this.textBox_input.SelectAll();

            try
            {
                this._taskList.AddTask(task);
            }
            catch (LockException)
            {
                Delegate_DoAction d = new Delegate_DoAction(_doAction);
                this.BeginInvoke(d, new object[] { func, strText, strTaskID });
            }
        }
Beispiel #6
0
        // 创建读者摘要
        internal List<PatronSummary> BuildPatronSummary(ChargingTask exclude_task)
        {
            List<PatronSummary> results = new List<PatronSummary>();
            PatronSummary current_summary = null;
            foreach (DpRow row in this.dpTable_tasks.Rows)
            {
                ChargingTask task = (ChargingTask)row.Tag;
                if (task == null)
                    continue;
                if (task == exclude_task)
                    continue;

                if (task.Action == "load_reader_info")
                {
                    // 为前一个读者
                    if (current_summary != null)
                        current_summary.RefreshColorList();

                    current_summary = new PatronSummary();
                    current_summary.Name = task.ReaderName;
                    current_summary.Barcode = task.ReaderBarcode;
                    current_summary.Tasks.Add(task);
                    results.Add(current_summary);

                    continue;
                }

                if (current_summary != null)
                    current_summary.Tasks.Add(task);
            }

            if (current_summary != null)
                current_summary.RefreshColorList();
            return results;
        }
Beispiel #7
0
        // 借书
        void Borrow(ChargingTask task)
        {
            DateTime start_time = DateTime.Now;

            List<DateTime> times = new List<DateTime>();
            times.Add(start_time);

            task.State = "begin";
            task.Color = "purple";  //  "light";
            this.Container.DisplayTask("refresh", task);
            this.Container.SetColorList();

            string strOperText = task.ReaderBarcode + " 借 " + task.ItemBarcode;

#if NO
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial(strOperText + " ...");
            stop.BeginLoop();
            try
            {
#endif
            stop.SetMessage(strOperText + " ...");

            string strError = "";

            string strReaderRecord = "";
            string strConfirmItemRecPath = null;

            bool bRenew = false;
            if (task.Action == "renew" || task.Action == "verify_renew")
                bRenew = true;

            if (task.Action == "renew")
                task.ReaderBarcode = "";
            else
            {
                if (string.IsNullOrEmpty(task.ReaderBarcode) == true)
                {
                    strError = "证条码号为空,无法进行借书操作";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
            }

        REDO:
            string[] aDupPath = null;
            string[] item_records = null;
            string[] reader_records = null;
            string[] biblio_records = null;
            string strOutputReaderBarcode = "";

            BorrowInfo borrow_info = null;

            // item返回的格式
            string strItemReturnFormats = "";

            if (this.Container.MainForm.ChargingNeedReturnItemXml == true)
            {
                if (String.IsNullOrEmpty(strItemReturnFormats) == false)
                    strItemReturnFormats += ",";
                strItemReturnFormats += "xml" + GetPostFix();
            }

            // biblio返回的格式
            string strBiblioReturnFormats = "";

            // 读者返回格式
            string strReaderFormatList = "";
            bool bName = false; // 是否直接取得读者姓名,而不要获得读者 XML
            if (this.Container.MainForm.ServerVersion >= 2.24)
            {
                strReaderFormatList = this.Container.PatronRenderFormat + ",summary";
                bName = true;
            }
            else
                strReaderFormatList = this.Container.PatronRenderFormat + ",xml" + GetPostFix();

            string strStyle = "reader";

            if (this.Container.MainForm.ChargingNeedReturnItemXml)
                strStyle += ",item";

            //if (this.Container.MainForm.TestMode == true)
            //    strStyle += ",testmode";
            times.Add(DateTime.Now);

            long lRet = Channel.Borrow(
stop,
bRenew,
task.ReaderBarcode,
task.ItemBarcode,
strConfirmItemRecPath,
false,
null,   // this.OneReaderItemBarcodes,
strStyle,
strItemReturnFormats,
out item_records,
strReaderFormatList,    // this.Container.PatronRenderFormat + ",xml" + GetPostFix(),
out reader_records,
strBiblioReturnFormats,
out biblio_records,
out aDupPath,
out strOutputReaderBarcode,
out borrow_info,
out strError);
            task.ErrorInfo = strError;

            times.Add(DateTime.Now);

            if (reader_records != null && reader_records.Length > 0)
                strReaderRecord = reader_records[0];

            // 刷新读者信息
            if (this.Container.IsCardMode == true)
            {
                if (String.IsNullOrEmpty(strReaderRecord) == false)
                    this.Container.SetReaderCardString(strReaderRecord);
            }
            else
            {
                if (String.IsNullOrEmpty(strReaderRecord) == false)
                    this.Container.SetReaderHtmlString(ReplaceMacro(strReaderRecord));
            }

            string strItemXml = "";
            if (this.Container.MainForm.ChargingNeedReturnItemXml == true
                && item_records != null)
            {
                Debug.Assert(item_records != null, "");

                if (item_records.Length > 0)
                {
                    // xml总是在最后一个
                    strItemXml = item_records[item_records.Length - 1];
                }
            }

            if (lRet == -1)
                goto ERROR1;

            DateTime end_time = DateTime.Now;

            string strReaderSummary = "";
            if (reader_records != null && reader_records.Length > 1)
            {
                if (bName == false)
                    strReaderSummary = Global.GetReaderSummary(reader_records[1]);
                else
                    strReaderSummary = reader_records[1];
            }

#if NO
                string strBiblioSummary = "";
                if (biblio_records != null && biblio_records.Length > 1)
                    strBiblioSummary = biblio_records[1];
#endif

            task.ReaderName = strReaderSummary;
            // task.ItemSummary = strBiblioSummary;
            this.Container.AsynFillItemSummary(task.ItemBarcode,
                strConfirmItemRecPath,
                task);

            this.Container.MainForm.OperHistory.BorrowAsync(
this.Container,
bRenew,
strOutputReaderBarcode,
task.ItemBarcode,
strConfirmItemRecPath,
strReaderSummary,
strItemXml,
borrow_info,
start_time,
end_time);

            /*
            lRet = 1;
            task.ErrorInfo = "asdf a asdf asdf as df asdf as f a df asdf a sdf a sdf asd f asdf a sdf as df";
            */

            if (lRet == 1)
            {
                // 黄色状态
                task.Color = "yellow";
            }
            else
            {
                // 绿色状态
                task.Color = "green";
            }

            // this.m_strCurrentBarcode = strBarcode;
            task.State = "finish";
            // 兑现显示
            this.Container.DisplayTask("refresh_and_visible", task);
            this.Container.SetColorList();
#if NO
                if (stop != null && stop.State != 0)
                    return true;
                return false;
#endif

            {
                BorrowCompleteEventArgs e1 = new BorrowCompleteEventArgs();
                e1.Action = task.Action;
                e1.ItemBarcode = task.ItemBarcode;
                e1.ReaderBarcode = strOutputReaderBarcode;
                this.Container.TriggerBorrowComplete(e1);
            }

            times.Add(DateTime.Now);
            LogOperTime("borrow", times, strOperText);

            return;
        ERROR1:
            task.State = "error";
            task.Color = "red";
            // this.Container.SetReaderRenderString(strError);
            // 兑现显示
            this.Container.DisplayTask("refresh_and_visible", task);
            this.Container.SetColorList();
#if NO
                if (stop != null && stop.State != 0)
                    return true;
                return false;
#endif
            return;

#if NO
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
#endif

        }
Beispiel #8
0
        // 响应一个任务状态的改变
        public void OnTaskStateChanged(string strAction, ChargingTask task)
        {
            if (this.PatronSummaries == null)
                return;

            foreach (PatronSummary summary in this.PatronSummaries)
            {
                if (summary.Tasks.IndexOf(task) != -1)
                {
                    if (strAction == "remove")
                        summary.RemoveTask(task);
                    else if (strAction == "refresh"
                        || strAction == "refresh_and_visible")
                        summary.RefreshColorList();
                    return;
                }
            }
        }
Beispiel #9
0
        internal void AsynFillItemSummary(string strItemBarcode, 
            string strConfirmItemRecPath,
            ChargingTask task)
        {
            if (this.IsDisposed)
                return;

            // 这里被做事的线程调用,希望启动任务后尽快返回。但不应把长时任务交给界面线程
            if (this.InvokeRequired)
            {
                Delegate_FillItemSummary d = new Delegate_FillItemSummary(AsynFillItemSummary);
                this.BeginInvoke(d, 
                    new object[] { 
                        strItemBarcode,
                        strConfirmItemRecPath,
                        task }
                    );
                return;
            }

            DpRow row = FindTaskLine(task);
            if (row == null)
                return;

            string strError = "";
            string strSummary = "";
            int nRet = GetBiblioSummary(strItemBarcode,
                strConfirmItemRecPath,
                out strSummary,
                out strError);
            if (nRet == -1)
                strSummary = strError;

            task.ItemSummary = strSummary;
            DisplayTask("refresh", task);

            if (this.SpeakBookTitle == true && nRet != -1
                && string.IsNullOrEmpty(strSummary) == false)
            {
                string strTitle = "";
                nRet = strSummary.IndexOf("/");
                if (nRet != -1)
                    strTitle = strSummary.Substring(0, nRet).Trim();
                else
                    strTitle = strSummary.Trim();

                this.MainForm.Speak(strTitle);
            }
        }
Beispiel #10
0
        // 还书
        void Return(ChargingTask task)
        {
            DateTime start_time = DateTime.Now;

            List <DateTime> times = new List <DateTime>();

            times.Add(start_time);

            task.State = "begin";
            task.Color = "purple";  //  "light";
            this.Container.DisplayTask("refresh", task);
            this.Container.SetColorList();

            string strOperText = "";

            if (task.Action == "inventory")
            {
                strOperText = task.ReaderBarcode + " 盘点 " + task.ItemBarcode;
            }
            else if (task.Action == "read")
            {
                if (StringUtil.CompareVersion(Program.MainForm.ServerVersion, "2.68") < 0)
                {
                    task.ErrorInfo = "操作未能进行。“读过”功能要求 dp2library 版本在 2.68 或以上";
                    goto ERROR1;
                }

                strOperText = task.ReaderBarcode + " 读过 " + task.ItemBarcode;
            }
            else if (task.Action == "boxing")
            {
                if (StringUtil.CompareVersion(Program.MainForm.ServerVersion, "2.92") < 0)
                {
                    task.ErrorInfo = "操作未能进行。“配书”功能要求 dp2library 版本在 2.92 或以上";
                    goto ERROR1;
                }

                strOperText = task.ReaderBarcode + " 配书 " + task.ItemBarcode;
            }
            else
            {
                strOperText = task.ReaderBarcode + " 还 " + task.ItemBarcode;
            }

#if NO
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial(strOperText + " ...");
            stop.BeginLoop();
            try
            {
#endif
            stop.SetMessage(strOperText + " ...");

            string strError = "";

            string strReaderRecord       = "";
            string strConfirmItemRecPath = null;

            string strAction        = task.Action;
            string strReaderBarcode = task.ReaderBarcode;
            if (task.Action == "verify_return")
            {
                if (string.IsNullOrEmpty(strReaderBarcode) == true)
                {
                    strError       = "尚未输入读者证条码号";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
                strAction = "return";
            }
            else if (task.Action == "verify_lost")
            {
                if (string.IsNullOrEmpty(strReaderBarcode) == true)
                {
                    strError       = "尚未输入读者证条码号";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
                strAction = "lost";
            }
            else if (task.Action == "inventory")
            {
                if (string.IsNullOrEmpty(strReaderBarcode) == true)
                {
                    strError       = "尚未设定批次号";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
                strAction = "inventory";
            }
            else if (task.Action == "read")
            {
                if (string.IsNullOrEmpty(strReaderBarcode) == true)
                {
                    strError       = "尚未输入读者证条码号";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
                strAction = "read";
            }
            else
            {
                strReaderBarcode = "";
            }

            //REDO:
            string[] aDupPath             = null;
            string[] item_records         = null;
            string[] reader_records       = null;
            string[] biblio_records       = null;
            string strOutputReaderBarcode = "";

            ReturnInfo return_info = null;

            // item返回的格式
            string strItemReturnFormats = "";

            if (this.Container.MainForm.ChargingNeedReturnItemXml == true)
            {
                if (String.IsNullOrEmpty(strItemReturnFormats) == false)
                {
                    strItemReturnFormats += ",";
                }
                strItemReturnFormats += "xml" + GetPostFix();
            }

            // biblio返回的格式
            string strBiblioReturnFormats = "";

            // 读者返回格式
            string strReaderFormatList = "";
            bool bName = false; // 是否直接取得读者姓名,而不要获得读者 XML
            if (StringUtil.CompareVersion(this.Container.MainForm.ServerVersion, "2.24") >= 0)
            {
                strReaderFormatList = this.Container.PatronRenderFormat + ",summary";
                bName = true;
            }
            else
            {
                strReaderFormatList = this.Container.PatronRenderFormat + ",xml" + GetPostFix();
            }

            string strStyle = "reader";

            if (this.Container.MainForm.ChargingNeedReturnItemXml)
            {
                strStyle += ",item";
            }

            if (string.IsNullOrEmpty(task.Parameters) == false)
            {
                strStyle += "," + task.Parameters;
            }

#if NO
            if (strAction == "inventory")
            {
                strItemReturnFormats = "xml";
                strStyle            += ",item";
            }
#endif

            //if (this.Container.MainForm.TestMode == true)
            //    strStyle += ",testmode";

            times.Add(DateTime.Now);

            long lRet = Channel.Return(
                stop,
                strAction,
                strReaderBarcode,
                task.ItemBarcode,
                strConfirmItemRecPath,
                false,
                strStyle,   // this.NoBiblioAndItemInfo == false ? "reader,item,biblio" : "reader",
                strItemReturnFormats,
                out item_records,
                strReaderFormatList,    // this.Container.PatronRenderFormat + ",xml" + GetPostFix(), // "html",
                out reader_records,
                strBiblioReturnFormats,
                out biblio_records,
                out aDupPath,
                out strOutputReaderBarcode,
                out return_info,
                out strError);

            if (lRet != 0)
            {
                task.ErrorInfo = strError;
            }

#if NO
            if (return_info != null)
            {
                strLocation = StringUtil.GetPureLocation(return_info.Location);
            }
#endif
            times.Add(DateTime.Now);

            if (reader_records != null && reader_records.Length > 0)
            {
                strReaderRecord = reader_records[0];
            }

            // 刷新读者信息
            if (this.Container.IsCardMode == true)
            {
                if (String.IsNullOrEmpty(strReaderRecord) == false)
                {
                    this.Container.SetReaderCardString(strReaderRecord);
                }
            }
            else
            {
                if (String.IsNullOrEmpty(strReaderRecord) == false)
                {
                    this.Container.SetReaderHtmlString(ReplaceMacro(strReaderRecord));
                }
            }

            string strItemXml = "";
            if ((this.Container.MainForm.ChargingNeedReturnItemXml == true || strAction == "inventory") &&
                item_records != null)
            {
                Debug.Assert(item_records != null, "");

                if (item_records.Length > 0)
                {
                    // xml总是在最后一个
                    strItemXml = item_records[item_records.Length - 1];
                }
            }

            // 对 return_info.Location 进行观察,看看是否超过要求的范围
            if (lRet != -1 &&
                strAction == "inventory" &&
                Container.FilterLocations != null &&
                Container.FilterLocations.Count > 0)
            {
#if NO
                XmlDocument item_dom = new XmlDocument();
                try
                {
                    item_dom.LoadXml(strItemXml);
                }
                catch (Exception ex)
                {
                    strError = "strItemXml 装入 XMLDOM 时出错: " + ex.Message;
                    goto ERROR1;
                }
                string strLocation = DomUtil.GetElementText(item_dom.DocumentElement, "location");
#endif
                string strLocation = return_info.Location;
                strLocation = StringUtil.GetPureLocation(strLocation);

                if (Container.FilterLocations.IndexOf(strLocation) == -1)
                {
                    lRet = 1;
                    if (string.IsNullOrEmpty(task.ErrorInfo) == false)
                    {
                        task.ErrorInfo += "; ";
                    }
                    task.ErrorInfo += "册记录中的馆藏地 '" + strLocation + "' 不在当前盘点要求的范围 '" + StringUtil.MakePathList(Container.FilterLocations) + "'。请及时处理";
                }
            }

            if (lRet == -1)
            {
                goto ERROR1;
            }

            string strReaderSummary = "";
            if (reader_records != null && reader_records.Length > 1)
            {
                if (bName == false)
                {
                    strReaderSummary = Global.GetReaderSummary(reader_records[1]);
                }
                else
                {
                    strReaderSummary = reader_records[1];
                }
            }

#if NO
            string strBiblioSummary = "";
            if (biblio_records != null && biblio_records.Length > 1)
            {
                strBiblioSummary = biblio_records[1];
            }
#endif

            task.ReaderName = strReaderSummary;
            // task.ItemSummary = strBiblioSummary;
#if NO
            this.Container.AsynFillItemSummary(task.ItemBarcode,
                                               strConfirmItemRecPath,
                                               task);
#endif
            this.Container.AddItemSummaryTask(task.ItemBarcode,
                                              strConfirmItemRecPath,
                                              task);

            if (string.IsNullOrEmpty(task.ReaderBarcode) == true)
            {
                task.ReaderBarcode = strOutputReaderBarcode;
            }

            DateTime end_time = DateTime.Now;

            this.Container.MainForm.OperHistory.ReturnAsync(
                this.Container,
                strAction,              // task.Action == "lost" || task.Action == "verify_lost",
                strOutputReaderBarcode, // this.textBox_readerBarcode.Text,
                task.ItemBarcode,
                strConfirmItemRecPath,
                strReaderSummary,
                strItemXml,
                return_info,
                start_time,
                end_time);

            if (lRet == 1)
            {
                // 黄色状态
                task.Color = "yellow";
            }
            else
            {
                // 绿色状态
                task.Color = "green";
            }

            // this.m_strCurrentBarcode = strBarcode;
            task.State = "finish";
            // 兑现显示
            this.Container.DisplayTask("refresh_and_visible", task);
            this.Container.SetColorList();
#if NO
            if (stop != null && stop.State != 0)
            {
                return(true);
            }
            return(false);
#endif
            {
                BorrowCompleteEventArgs e1 = new BorrowCompleteEventArgs();
                e1.Action        = task.Action;
                e1.ItemBarcode   = task.ItemBarcode;
                e1.ReaderBarcode = strOutputReaderBarcode;
                this.Container.TriggerBorrowComplete(e1);
            }

            times.Add(DateTime.Now);
            LogOperTime("return", times, strOperText);
            return;

ERROR1:
            task.State = "error";
            task.Color = "red";
            // this.Container.SetReaderRenderString(strError);
            // 兑现显示
            this.Container.DisplayTask("refresh_and_visible", task);
            this.Container.SetColorList();
#if NO
            if (stop != null && stop.State != 0)
            {
                return(true);
            }
            return(false);
#endif
            return;

#if NO
        }

        finally
        {
            stop.EndLoop();
            stop.OnStop -= new StopEventHandler(this.DoStop);
            stop.Initial("");
        }
#endif
        }
Beispiel #11
0
 public void RemoveTask(ChargingTask task, bool bLock = true)
 {
     if (bLock == true)
     {
         if (this.m_lock.TryEnterWriteLock(m_nLockTimeout) == false)
             throw new LockException("锁定尝试中超时");
     }
     try
     {
         this._tasks.Remove(task);
     }
     finally
     {
         if (bLock == true)
             this.m_lock.ExitWriteLock();
     } 
     
     // 兑现显示
     this.Container.DisplayTask("remove", task);
     this.Container.SetColorList();
 }
Beispiel #12
0
        // 加入一个任务到列表中
        public void AddTask(ChargingTask task)
        {
            task.Color = "black";   // 表示等待处理
            if (this.m_lock.TryEnterWriteLock(500) == false)   // m_nLockTimeout
                throw new LockException("锁定尝试中超时");
            try
            {
                this._tasks.Add(task);
            }
            finally
            {
                this.m_lock.ExitWriteLock();
            }

            // 触发任务开始执行
            this.Activate();

            // 兑现显示
            this.Container.DisplayTask("add", task);
            this.Container.SetColorList();
        }
Beispiel #13
0
        // 还书
        void Return(ChargingTask task)
        {
            DateTime start_time = DateTime.Now;

            List<DateTime> times = new List<DateTime>();
            times.Add(start_time);

            task.State = "begin";
            task.Color = "purple";  //  "light";
            this.Container.DisplayTask("refresh", task);
            this.Container.SetColorList();

            string strOperText = "";

            if (task.Action == "inventory")
                strOperText = task.ReaderBarcode + " 盘点 " + task.ItemBarcode;
            else
                strOperText = task.ReaderBarcode + " 还 " + task.ItemBarcode;

#if NO
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial(strOperText + " ...");
            stop.BeginLoop();
            try
            {
#endif
            stop.SetMessage(strOperText + " ...");

            string strError = "";

            string strReaderRecord = "";
            string strConfirmItemRecPath = null;

            string strAction = task.Action;
            string strReaderBarcode = task.ReaderBarcode;
            if (task.Action == "verify_return")
            {
                if (string.IsNullOrEmpty(strReaderBarcode) == true)
                {
                    strError = "尚未输入读者证条码号";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
                strAction = "return";
            }
            else if (task.Action == "verify_lost")
            {
                if (string.IsNullOrEmpty(strReaderBarcode) == true)
                {
                    strError = "尚未输入读者证条码号";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
                strAction = "lost";
            }
            else if (task.Action == "inventory")
            {
                if (string.IsNullOrEmpty(strReaderBarcode) == true)
                {
                    strError = "尚未设定批次号";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
                strAction = "inventory";
            }
            else
            {
                strReaderBarcode = "";
            }
        REDO:
            string[] aDupPath = null;
            string[] item_records = null;
            string[] reader_records = null;
            string[] biblio_records = null;
            string strOutputReaderBarcode = "";

            ReturnInfo return_info = null;

            // item返回的格式
            string strItemReturnFormats = "";

            if (this.Container.MainForm.ChargingNeedReturnItemXml == true)
            {
                if (String.IsNullOrEmpty(strItemReturnFormats) == false)
                    strItemReturnFormats += ",";
                strItemReturnFormats += "xml" + GetPostFix();
            }

            // biblio返回的格式
            string strBiblioReturnFormats = "";

            // 读者返回格式
            string strReaderFormatList = "";
            bool bName = false; // 是否直接取得读者姓名,而不要获得读者 XML
            if (this.Container.MainForm.ServerVersion >= 2.24)
            {
                strReaderFormatList = this.Container.PatronRenderFormat + ",summary";
                bName = true;
            }
            else
                strReaderFormatList = this.Container.PatronRenderFormat + ",xml" + GetPostFix();

            string strStyle = "reader";

            if (this.Container.MainForm.ChargingNeedReturnItemXml)
                strStyle += ",item";

#if NO
            if (strAction == "inventory")
            {
                strItemReturnFormats = "xml";
                strStyle += ",item";
            }
#endif

            //if (this.Container.MainForm.TestMode == true)
            //    strStyle += ",testmode";

            times.Add(DateTime.Now);

            long lRet = Channel.Return(
                stop,
                strAction,
                strReaderBarcode,
                task.ItemBarcode,
                strConfirmItemRecPath,
                false,
                strStyle,   // this.NoBiblioAndItemInfo == false ? "reader,item,biblio" : "reader",
                strItemReturnFormats,
                out item_records,
                strReaderFormatList,    // this.Container.PatronRenderFormat + ",xml" + GetPostFix(), // "html",
                out reader_records,
                strBiblioReturnFormats,
                out biblio_records,
                out aDupPath,
                out strOutputReaderBarcode,
                out return_info,
                out strError);

            if (lRet != 0)
                task.ErrorInfo = strError;

#if NO
                if (return_info != null)
                {
                    strLocation = StringUtil.GetPureLocation(return_info.Location);
                }
#endif
            times.Add(DateTime.Now);

            if (reader_records != null && reader_records.Length > 0)
                strReaderRecord = reader_records[0];

            // 刷新读者信息
            if (this.Container.IsCardMode == true)
            {
                if (String.IsNullOrEmpty(strReaderRecord) == false)
                    this.Container.SetReaderCardString(strReaderRecord);
            }
            else
            {
                if (String.IsNullOrEmpty(strReaderRecord) == false)
                    this.Container.SetReaderHtmlString(ReplaceMacro(strReaderRecord));
            }

            string strItemXml = "";
            if ((this.Container.MainForm.ChargingNeedReturnItemXml == true || strAction == "inventory")
                && item_records != null)
            {
                Debug.Assert(item_records != null, "");

                if (item_records.Length > 0)
                {
                    // xml总是在最后一个
                    strItemXml = item_records[item_records.Length - 1];
                }
            }

            // 对 return_info.Location 进行观察,看看是否超过要求的范围
            if (lRet != -1
                && strAction == "inventory"
                && Container.FilterLocations != null
                && Container.FilterLocations.Count > 0)
            {
#if NO
                XmlDocument item_dom = new XmlDocument();
                try
                {
                    item_dom.LoadXml(strItemXml);
                }
                catch(Exception ex)
                {
                    strError = "strItemXml 装入 XMLDOM 时出错: " + ex.Message;
                    goto ERROR1;
                }
                string strLocation = DomUtil.GetElementText(item_dom.DocumentElement, "location");
#endif
                string strLocation = return_info.Location;
                strLocation = StringUtil.GetPureLocation(strLocation);

                if (Container.FilterLocations.IndexOf(strLocation) == -1)
                {
                    lRet = 1;
                    if (string.IsNullOrEmpty(task.ErrorInfo) == false)
                        task.ErrorInfo += "; ";
                    task.ErrorInfo += "册记录中的馆藏地 '" + strLocation + "' 不在当前盘点要求的范围 '" + StringUtil.MakePathList(Container.FilterLocations) + "'。请及时处理";
                }
            }

            if (lRet == -1)
                goto ERROR1;

            string strReaderSummary = "";
            if (reader_records != null && reader_records.Length > 1)
            {
                if (bName == false)
                    strReaderSummary = Global.GetReaderSummary(reader_records[1]);
                else
                    strReaderSummary = reader_records[1];
            }

#if NO
                string strBiblioSummary = "";
                if (biblio_records != null && biblio_records.Length > 1)
                    strBiblioSummary = biblio_records[1];
#endif

            task.ReaderName = strReaderSummary;
            // task.ItemSummary = strBiblioSummary;
            this.Container.AsynFillItemSummary(task.ItemBarcode,
                strConfirmItemRecPath,
                task);

            if (string.IsNullOrEmpty(task.ReaderBarcode) == true)
                task.ReaderBarcode = strOutputReaderBarcode;

            DateTime end_time = DateTime.Now;

            this.Container.MainForm.OperHistory.ReturnAsync(
                this.Container,
                strAction,  // task.Action == "lost" || task.Action == "verify_lost",
                strOutputReaderBarcode, // this.textBox_readerBarcode.Text,
                task.ItemBarcode,
                strConfirmItemRecPath,
                strReaderSummary,
                strItemXml,
                return_info,
                start_time,
                end_time);

            if (lRet == 1)
            {
                // 黄色状态
                task.Color = "yellow";
            }
            else
            {
                // 绿色状态
                task.Color = "green";
            }

            // this.m_strCurrentBarcode = strBarcode;
            task.State = "finish";
            // 兑现显示
            this.Container.DisplayTask("refresh_and_visible", task);
            this.Container.SetColorList();
#if NO
                if (stop != null && stop.State != 0)
                    return true;
                return false;
#endif
            {
                BorrowCompleteEventArgs e1 = new BorrowCompleteEventArgs();
                e1.Action = task.Action;
                e1.ItemBarcode = task.ItemBarcode;
                e1.ReaderBarcode = strOutputReaderBarcode;
                this.Container.TriggerBorrowComplete(e1);
            }

            times.Add(DateTime.Now);
            LogOperTime("return", times, strOperText);

            return;

        ERROR1:
            task.State = "error";
            task.Color = "red";
            // this.Container.SetReaderRenderString(strError);
            // 兑现显示
            this.Container.DisplayTask("refresh_and_visible", task);
            this.Container.SetColorList();
#if NO
                if (stop != null && stop.State != 0)
                    return true;
                return false;
#endif
            return;
#if NO
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
#endif
        }
Beispiel #14
0
        internal void DisplayReaderSummary(ChargingTask exclude_task,
            string strText)
        {
            if (this.IsDisposed)
                return;

            if (this.InvokeRequired)
            {
                Delegate_DisplayReaderSummary d = new Delegate_DisplayReaderSummary(DisplayReaderSummary);
                this.BeginInvoke(d,
                    new object[] { exclude_task, strText }
                    );
                return;
            }

            List<PatronSummary> summaries = BuildPatronSummary(exclude_task);

            if (_patronSummaryForm == null)
            {
                _patronSummaryForm = new PatronSummaryForm();
                _patronSummaryForm.FormClosed -= new FormClosedEventHandler(_patronSummaryForm_FormClosed);
                _patronSummaryForm.FormClosed += new FormClosedEventHandler(_patronSummaryForm_FormClosed);
                // _patronSummaryForm.Show(this);
            }

            _patronSummaryForm.PatronSummaries = summaries;
            _patronSummaryForm.Font = this.Font;


            if (_patronSummaryForm.Visible == false)
            {
                this.MainForm.AppInfo.LinkFormState(this._patronSummaryForm, "_patronSummaryForm_state");
                if (_patronSummaryForm.IsDisposed)
                    return;
                _patronSummaryForm.Show(this);
            }
            else
                _patronSummaryForm.FillList();

            _patronSummaryForm.Comment = strText;
            _patronSummaryForm.ShowComment();
        }
Beispiel #15
0
        // 装载读者信息
        // return:
        //      false   正常
        //      true    需要停止后继的需要通道的操作
        void LoadReaderInfo(ChargingTask task)
        {
            task.State = "begin";
            task.Color = "purple";    // "light";
            this.Container.DisplayTask("refresh", task);
            this.Container.SetColorList();

#if NO
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("装入读者信息 " + task.ReaderBarcode + "...");
            stop.BeginLoop();
            try
            {
#endif
            stop.SetMessage("装入读者信息 " + task.ReaderBarcode + "...");

            string strError = "";

            if (this.Container.IsCardMode == true)
            {
                this.Container.SetReaderCardString("");
            }
            else
            {
                this.Container.SetReaderHtmlString("(空)");
            }

            string strStyle = this.Container.PatronRenderFormat;
            if (this.Container.SpeakPatronName == true)
            {
                strStyle += ",summary";
            }
            {
                strStyle += ",xml";
                if (StringUtil.CompareVersion(this.Container.MainForm.ServerVersion, "2.25") >= 0)
                {
                    strStyle += ":noborrowhistory";
                }
            }
#if NO
            if (this.VoiceName == true)
            {
                strStyle += ",summary";
            }
#endif

            stop.SetMessage("正在装入读者记录 " + task.ReaderBarcode + " ...");

            string[] results   = null;
            byte[] baTimestamp = null;
            string strRecPath  = "";
            long lRet          = this.Channel.GetReaderInfo(
                stop,
                GetRequestPatronBarcode(task.ReaderBarcode),
                strStyle,   // this.RenderFormat, // "html",
                out results,
                out strRecPath,
                out baTimestamp,
                out strError);

            task.ErrorInfo = strError;

            if (lRet == 0)
            {
                if (StringUtil.IsIdcardNumber(task.ReaderBarcode) == true)
                {
                    task.ErrorInfo = ("证条码号(或身份证号)为 '" + task.ReaderBarcode + "' 的读者记录没有找到 ...");
                }
                else
                {
                    task.ErrorInfo = ("证条码号为 '" + task.ReaderBarcode + "' 的读者记录没有找到 ...");
                }

                goto ERROR1;   // not found
            }
            if (lRet == -1)
            {
                goto ERROR1;
            }

            if (results == null || results.Length == 0)
            {
                strError = "返回的results不正常。";
                goto ERROR1;
            }
            string strResult = "";
            strResult = results[0];
            string strReaderXml = results[results.Length - 1];

            if (lRet > 1)
            {
                string strBarcode = "";
                // return:
                //      -1  error
                //      0   放弃
                //      1   成功
                int nRet = this.Container.SelectOnePatron(lRet,
                                                          strRecPath,
                                                          out strBarcode,
                                                          out strResult,
                                                          out strError);
                if (nRet == -1)
                {
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
                if (nRet == 0)
                {
                    strError       = "放弃装入读者记录";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }

                if (task.ReaderBarcode != strBarcode)
                {
                    task.ReaderBarcode = strBarcode;

                    // TODO: 此时 task.ReaderXml 需要另行获得
                    strReaderXml = "";

                    strStyle = "xml";
                    if (StringUtil.CompareVersion(this.Container.MainForm.ServerVersion, "2.25") >= 0)
                    {
                        strStyle += ":noborrowhistory";
                    }
                    results = null;

                    lRet = this.Channel.GetReaderInfo(
                        stop,
                        strBarcode,
                        strStyle, // this.RenderFormat, // "html",
                        out results,
                        out strRecPath,
                        out baTimestamp,
                        out strError);
                    if (lRet == 1 && results != null && results.Length >= 1)
                    {
                        strReaderXml = results[0];
                    }
                }
            }
            else
            {
                // 检查用户输入的 barcode 是否和读者记录里面的 barcode 吻合
            }

            task.ReaderXml = strReaderXml;

            if (string.IsNullOrEmpty(strReaderXml) == false)
            {
                task.ReaderName = Global.GetReaderSummary(strReaderXml);
            }

            if (this.Container.IsCardMode == true)
            {
                this.Container.SetReaderCardString(strReaderXml);
            }
            else
            {
                this.Container.SetReaderHtmlString(ReplaceMacro(strResult));
            }

            // 如果切换了读者
            // if (this.CurrentReaderBarcode != task.ReaderBarcode)
            {
                // 删除除了本任务以外的其他任务
                // TODO: 需要检查这些任务中是否有尚未完成的
                List <ChargingTask> tasks = new List <ChargingTask>();
                tasks.AddRange(this._tasks);
                tasks.Remove(task);

                int nCount = CountNotFinishTasks(tasks);
                if (nCount > 0)
                {
#if NO
                    if (this.Container.AskContinue("当前有 " + nCount.ToString() + " 个任务尚未完成。\r\n\r\n是否清除这些任务并继续?") == DialogResult.Cancel)
                    {
                        strError       = "装入读者记录的操作被中断";
                        task.ErrorInfo = strError;
                        goto ERROR1;
                    }
#endif
                    this.Container.DisplayReaderSummary(task, "前面读者有 " + nCount.ToString() + " 个任务尚未完成,或有提示需要进一步处理。\r\n点击此处查看摘要信息");
                }
                else
                {
                    this.Container.ClearTaskList(tasks);
                }
            }

            this.CurrentReaderBarcode = task.ReaderBarcode; // 会自动显示出来

            if (this.Container.SpeakPatronName == true && results.Length >= 2)
            {
                string strName = results[1];
                this.Container.MainForm.Speak(strName);
            }

            // this.m_strCurrentBarcode = strBarcode;
            task.State = "finish";
            task.Color = "";
            // 兑现显示
            this.Container.DisplayTask("refresh", task);
            this.Container.SetColorList();
            // this.Container.CurrentReaderBarcodeChanged(this.CurrentReaderBarcode);  // 通知 读者记录已经成功装载
#if NO
            if (stop != null && stop.State != 0)
            {
                return(true);
            }
            return(false);
#endif
            return;

ERROR1:
            task.State = "error";
            task.Color = "red";
            this.CurrentReaderBarcode = ""; // 及时清除上下文,避免后面错误借到先前的读者名下
            if (this.Container.IsCardMode == true)
            {
                this.Container.SetReaderCardString(task.ErrorInfo);
            }
            else
            {
                this.Container.SetReaderTextString(task.ErrorInfo);
            }
            // 兑现显示
            this.Container.DisplayTask("refresh", task);
            this.Container.SetColorList();
            this.Stopped = true;  // 全部任务停止处理。这是因为装载读者的操作比较重要,是后继操作的前提
#if NO
            if (stop != null && stop.State != 0)
            {
                return(true);
            }
            return(false);
#endif
            return;

#if NO
        }

        finally
        {
            stop.EndLoop();
            stop.OnStop -= new StopEventHandler(this.DoStop);
            stop.Initial("");
        }
#endif
        }
Beispiel #16
0
        internal void AddItemSummaryTask(string strItemBarcode,
            string strConfirmItemRecPath,
            ChargingTask charging_task,
            bool bClearBofore = true)
        {
            if (bClearBofore)
            {
                // 如果以前有摘要,要先清除。这样操作者在等待过程中能清楚当前处在什么状态
                charging_task.ItemSummary = "正在获取书目摘要 ...";
                DisplayTask("refresh", charging_task);
            }

            SummaryTask task = new SummaryTask();
            task.Action = "get_item_summary";
            task.ItemBarcode = strItemBarcode;
            task.ConfirmItemRecPath = strConfirmItemRecPath;
            task.ChargingTask = charging_task;

            this._summaryList.AddTask(task);
        }
Beispiel #17
0
        // 借书
        void Borrow(ChargingTask task)
        {
            DateTime start_time = DateTime.Now;

            List <DateTime> times = new List <DateTime>();

            times.Add(start_time);

            task.State = "begin";
            task.Color = "purple";  //  "light";
            this.Container.DisplayTask("refresh", task);
            this.Container.SetColorList();

            string strOperText = task.ReaderBarcode + " 借 " + task.ItemBarcode;

#if NO
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial(strOperText + " ...");
            stop.BeginLoop();
            try
            {
#endif
            stop.SetMessage(strOperText + " ...");

            string strError = "";

            string strReaderRecord       = "";
            string strConfirmItemRecPath = null;

            bool bRenew = false;
            if (task.Action == "renew" || task.Action == "verify_renew")
            {
                bRenew = true;
            }

            if (task.Action == "renew")
            {
                task.ReaderBarcode = "";
            }
            else
            {
                if (string.IsNullOrEmpty(task.ReaderBarcode) == true)
                {
                    strError       = "证条码号为空,无法进行借书操作";
                    task.ErrorInfo = strError;
                    goto ERROR1;
                }
            }

            // REDO:
            string[] aDupPath             = null;
            string[] item_records         = null;
            string[] reader_records       = null;
            string[] biblio_records       = null;
            string strOutputReaderBarcode = "";

            BorrowInfo borrow_info = null;

            // item返回的格式
            string strItemReturnFormats = "";

            if (this.Container.MainForm.ChargingNeedReturnItemXml == true)
            {
                if (String.IsNullOrEmpty(strItemReturnFormats) == false)
                {
                    strItemReturnFormats += ",";
                }
                strItemReturnFormats += "xml" + GetPostFix();
            }

            // biblio返回的格式
            string strBiblioReturnFormats = "";

            // 读者返回格式
            string strReaderFormatList = "";
            bool bName = false; // 是否直接取得读者姓名,而不要获得读者 XML
            if (StringUtil.CompareVersion(this.Container.MainForm.ServerVersion, "2.24") >= 0)
            {
                strReaderFormatList = this.Container.PatronRenderFormat + ",summary";
                bName = true;
            }
            else
            {
                strReaderFormatList = this.Container.PatronRenderFormat + ",xml" + GetPostFix();
            }

            string strStyle = "reader";

            if (this.Container.MainForm.ChargingNeedReturnItemXml)
            {
                strStyle += ",item";
            }

            //if (this.Container.MainForm.TestMode == true)
            //    strStyle += ",testmode";
            times.Add(DateTime.Now);

            long lRet = Channel.Borrow(
                stop,
                bRenew,
                task.ReaderBarcode,
                task.ItemBarcode,
                strConfirmItemRecPath,
                false,
                null, // this.OneReaderItemBarcodes,
                strStyle,
                strItemReturnFormats,
                out item_records,
                strReaderFormatList, // this.Container.PatronRenderFormat + ",xml" + GetPostFix(),
                out reader_records,
                strBiblioReturnFormats,
                out biblio_records,
                out aDupPath,
                out strOutputReaderBarcode,
                out borrow_info,
                out strError);
            task.ErrorInfo = strError;

            times.Add(DateTime.Now);

            if (reader_records != null && reader_records.Length > 0)
            {
                strReaderRecord = reader_records[0];
            }

            // 刷新读者信息
            if (this.Container.IsCardMode == true)
            {
                if (String.IsNullOrEmpty(strReaderRecord) == false)
                {
                    this.Container.SetReaderCardString(strReaderRecord);
                }
            }
            else
            {
                if (String.IsNullOrEmpty(strReaderRecord) == false)
                {
                    this.Container.SetReaderHtmlString(ReplaceMacro(strReaderRecord));
                }
            }

            string strItemXml = "";
            if (this.Container.MainForm.ChargingNeedReturnItemXml == true &&
                item_records != null)
            {
                Debug.Assert(item_records != null, "");

                if (item_records.Length > 0)
                {
                    // xml总是在最后一个
                    strItemXml = item_records[item_records.Length - 1];
                }
            }

            if (lRet == -1)
            {
                goto ERROR1;
            }

            DateTime end_time = DateTime.Now;

            string strReaderSummary = "";
            if (reader_records != null && reader_records.Length > 1)
            {
                if (bName == false)
                {
                    strReaderSummary = Global.GetReaderSummary(reader_records[1]);
                }
                else
                {
                    strReaderSummary = reader_records[1];
                }
            }

#if NO
            string strBiblioSummary = "";
            if (biblio_records != null && biblio_records.Length > 1)
            {
                strBiblioSummary = biblio_records[1];
            }
#endif

            task.ReaderName = strReaderSummary;
            // task.ItemSummary = strBiblioSummary;
#if NO
            this.Container.AsynFillItemSummary(task.ItemBarcode,
                                               strConfirmItemRecPath,
                                               task);
#endif
            this.Container.AddItemSummaryTask(task.ItemBarcode,
                                              strConfirmItemRecPath,
                                              task);

            this.Container.MainForm.OperHistory.BorrowAsync(
                this.Container,
                bRenew,
                strOutputReaderBarcode,
                task.ItemBarcode,
                strConfirmItemRecPath,
                strReaderSummary,
                strItemXml,
                borrow_info,
                start_time,
                end_time);

            /*
             * lRet = 1;
             * task.ErrorInfo = "asdf a asdf asdf as df asdf as f a df asdf a sdf a sdf asd f asdf a sdf as df";
             */

            if (lRet == 1)
            {
                // 黄色状态
                task.Color = "yellow";
            }
            else
            {
                // 绿色状态
                task.Color = "green";
            }

            // this.m_strCurrentBarcode = strBarcode;
            task.State = "finish";
            // 兑现显示
            this.Container.DisplayTask("refresh_and_visible", task);
            this.Container.SetColorList();
#if NO
            if (stop != null && stop.State != 0)
            {
                return(true);
            }
            return(false);
#endif

            {
                BorrowCompleteEventArgs e1 = new BorrowCompleteEventArgs();
                e1.Action        = task.Action;
                e1.ItemBarcode   = task.ItemBarcode;
                e1.ReaderBarcode = strOutputReaderBarcode;
                this.Container.TriggerBorrowComplete(e1);
            }

            times.Add(DateTime.Now);
            LogOperTime("borrow", times, strOperText);
            return;

ERROR1:
            task.State = "error";
            task.Color = "red";
            // this.Container.SetReaderRenderString(strError);
            // 兑现显示
            this.Container.DisplayTask("refresh_and_visible", task);
            this.Container.SetColorList();
#if NO
            if (stop != null && stop.State != 0)
            {
                return(true);
            }
            return(false);
#endif
            return;

#if NO
        }

        finally
        {
            stop.EndLoop();
            stop.OnStop -= new StopEventHandler(this.DoStop);
            stop.Initial("");
        }
#endif
        }
Beispiel #18
0
        // 把摘要显示到任务列表中,并朗读出来
        // parameters:
        //      bSpeak  是否要把 strSummary 朗读出来?注意,当此参数为 true 时,依然要看当前系统参数配置,允许朗读才真正朗读
        internal void AsyncFillItemSummary(ChargingTask task,
            string strSummary,
            bool bSpeak)
        {
            if (this.IsDisposed)
                return;

            // 这里被做事的线程调用,希望启动任务后尽快返回。但不应把长时任务交给界面线程
            if (this.InvokeRequired)
            {
                // 原来是 BeginInvoke。可能和清除文本的动作发生顺序交错
                this.Invoke(new Action<ChargingTask, string, bool>(AsyncFillItemSummary), task, strSummary, bSpeak);
                return;
            }

            DpRow row = FindTaskLine(task);
            if (row == null)
                return;

            task.ItemSummary = strSummary;
            DisplayTask("refresh", task);

            // 把摘要的书名部分朗读出来
            if (bSpeak
                && this.SpeakBookTitle == true
                && string.IsNullOrEmpty(strSummary) == false)
            {
                string strTitle = "";
                int nRet = strSummary.IndexOf("/");
                if (nRet != -1)
                    strTitle = strSummary.Substring(0, nRet).Trim();
                else
                    strTitle = strSummary.Trim();

                this.MainForm.Speak(strTitle);
            }
        }
Beispiel #19
0
        //
        // 在显示列表中操作一个 Task 行
        // parameters:
        //      strAction   add remove refresh refresh_and_visible
        internal void DisplayTask(string strAction,
            ChargingTask task)
        {
            if (this.IsDisposed)
                return;

            if (this.InvokeRequired)
            {
                Delegate_DisplayTask d = new Delegate_DisplayTask(_displayTask);
                this.Invoke(d, new object[] { strAction, task });
            }
            else
            {
                _displayTask(strAction, task);
            }
        }
Beispiel #20
0
 public void RemoveTask(ChargingTask task)
 {
     this.Tasks.Remove(task);
     this.RefreshColorList();
 }
Beispiel #21
0
        void _displayTask(string strAction, ChargingTask task)
        {
            if (strAction == "add")
            {
                DpRow line = new DpRow();
                line.Style = DpRowStyle.HorzGrid;
                line.BackColor = this.TaskBackColor;    // SystemColors.Window;
                line.ForeColor = this.TaskForeColor;
                task.RefreshDisplay(line);

                line.Tag = task;
                this.dpTable_tasks.Rows.Add(line);
                if (this._bScrollBarTouched == false)
                {
                    // TODO: 应该分为两种情况  希望看到最末事项的,和看中间的。信号是触动卷滚条到底部;拖动卷滚条到中部
                    this.dpTable_tasks.FocusedItem = line;
                    line.EnsureVisible();
                }
            }
            else if (strAction == "remove")
            {
                DpRow line = FindTaskLine(task);
                if (line != null)
                    this.dpTable_tasks.Rows.Remove(line);
                else
                {
                    // Debug.Assert(false, "");
                }
            }
            else if (strAction == "refresh"
                || strAction == "refresh_and_visible")
            {
                DpRow line = FindTaskLine(task);
                if (line != null)
                {
                    // 刷新显示
                    task.RefreshDisplay(line);

                    if (this.StateSpeak != "[不朗读]")
                    {
                        string strContent = task.GetSpeakContent(line, this.StateSpeak);
                        if (string.IsNullOrEmpty(strContent) == false)
                            this.MainForm.Speak(strContent);
                    }

                    if (task.Action == "load_reader_info" && string.IsNullOrEmpty(task.ReaderXml) == false)
                        task.RefreshPatronCardDisplay(line);

                    if (this._bScrollBarTouched == false)
                    {
                        // 如果刷新的对象是 Focus 对象,则确保显示在视野范围内
                        // TODO: 当发现中途人触动了控件时,这个功能要禁用,以免对人的操作发生干扰
                        if (this.dpTable_tasks.FocusedItem == line)
                            line.EnsureVisible();
                        else
                        {
                            if (strAction == "refresh_and_visible")
                                line.EnsureVisible();
                        }
                    }

                }

            }

            // 刷新读者摘要窗口
            if (this._patronSummaryForm != null
                && this._patronSummaryForm.Visible
                && strAction == "add")
                this._patronSummaryForm.OnTaskStateChanged(strAction, task);
        }
Beispiel #22
0
 public void RemoveTask(ChargingTask task)
 {
     this.Tasks.Remove(task);
     this.RefreshColorList();
 }
Beispiel #23
0
        // 装载读者信息
        // return:
        //      false   正常
        //      true    需要停止后继的需要通道的操作
        void LoadReaderInfo(ChargingTask task)
        {
            task.State = "begin";
            task.Color = "purple";    // "light";
            this.Container.DisplayTask("refresh", task);
            this.Container.SetColorList();

#if NO
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("装入读者信息 " +task.ReaderBarcode+ "...");
            stop.BeginLoop();
            try
            {
#endif
            stop.SetMessage("装入读者信息 " + task.ReaderBarcode + "...");

                string strError = "";

                if (this.Container.IsCardMode == true)
                    this.Container.SetReaderCardString("");
                else
                    this.Container.SetReaderHtmlString("(空)");

                string strStyle = this.Container.PatronRenderFormat;
                if (this.Container.SpeakPatronName == true)
                    strStyle += ",summary";
                strStyle += ",xml";
            if (this.Container.MainForm.ServerVersion >= 2.25)
            strStyle += ":noborrowhistory";
#if NO
            if (this.VoiceName == true)
                strStyle += ",summary";
#endif

                stop.SetMessage("正在装入读者记录 " + task.ReaderBarcode + " ...");

                string[] results = null;
                byte[] baTimestamp = null;
                string strRecPath = "";
                long lRet = this.Channel.GetReaderInfo(
                    stop,
                    GetRequestPatronBarcode(task.ReaderBarcode),
                    strStyle,   // this.RenderFormat, // "html",
                    out results,
                    out strRecPath,
                    out baTimestamp,
                    out strError);

                task.ErrorInfo = strError;

                if (lRet == 0)
                {
                     
                    if (StringUtil.IsIdcardNumber(task.ReaderBarcode) == true)
                        task.ErrorInfo = ("证条码号(或身份证号)为 '" + task.ReaderBarcode + "' 的读者记录没有找到 ...");
                    else
                        task.ErrorInfo = ("证条码号为 '" + task.ReaderBarcode + "' 的读者记录没有找到 ...");

                    goto ERROR1;   // not found
                }
                if (lRet == -1)
                    goto ERROR1;

                if (results == null || results.Length == 0)
                {
                    strError = "返回的results不正常。";
                    goto ERROR1;
                }
                string strResult = "";
                strResult = results[0];
                string strReaderXml = results[results.Length - 1];

                if (lRet > 1)
                {
                    string strBarcode = "";
                    // return:
                    //      -1  error
                    //      0   放弃
                    //      1   成功
                    int nRet = this.Container.SelectOnePatron(lRet,
                        strRecPath,
                        out strBarcode,
                        out strResult,
                        out strError);
                    if (nRet == -1)
                    {
                        task.ErrorInfo = strError;
                        goto ERROR1;
                    }
                    if (nRet == 0)
                    {
                        strError = "放弃装入读者记录";
                        task.ErrorInfo = strError;
                        goto ERROR1;
                    }

                    if (task.ReaderBarcode != strBarcode)
                    {
                        task.ReaderBarcode = strBarcode;

                        // TODO: 此时 task.ReaderXml 需要另行获得
                        strReaderXml = "";

                        strStyle = "xml";
            if (this.Container.MainForm.ServerVersion >= 2.25)
            strStyle += ":noborrowhistory";
                        results = null;

                        lRet = this.Channel.GetReaderInfo(
    stop,
    strBarcode,
    strStyle,   // this.RenderFormat, // "html",
    out results,
    out strRecPath,
    out baTimestamp,
    out strError);
                        if (lRet == 1 && results != null && results.Length >= 1)
                            strReaderXml = results[0];
                    }
                }
                else
                {
                    // 检查用户输入的 barcode 是否和读者记录里面的 barcode 吻合
                }

                task.ReaderXml = strReaderXml;

                if (string.IsNullOrEmpty(strReaderXml) == false)
                {
                    task.ReaderName = Global.GetReaderSummary(strReaderXml);
                }

                if (this.Container.IsCardMode == true)
                    this.Container.SetReaderCardString(strReaderXml);
                else 
                    this.Container.SetReaderHtmlString(ReplaceMacro(strResult));

                // 如果切换了读者
                // if (this.CurrentReaderBarcode != task.ReaderBarcode)
                {
                    // 删除除了本任务以外的其他任务
                    // TODO: 需要检查这些任务中是否有尚未完成的
                    List<ChargingTask> tasks = new List<ChargingTask>();
                    tasks.AddRange(this._tasks);
                    tasks.Remove(task);

                    int nCount = CountNotFinishTasks(tasks);
                    if (nCount > 0)
                    {
#if NO
                        if (this.Container.AskContinue("当前有 " + nCount.ToString()+ " 个任务尚未完成。\r\n\r\n是否清除这些任务并继续?") == DialogResult.Cancel)
                        {
                            strError = "装入读者记录的操作被中断";
                            task.ErrorInfo = strError;
                            goto ERROR1;
                        }
#endif
                        this.Container.DisplayReaderSummary(task, "前面读者有 " + nCount.ToString()+ " 个任务尚未完成,或有提示需要进一步处理。\r\n点击此处查看摘要信息");
                    }
                    else
                        this.Container.ClearTaskList(tasks);
                }

                this.CurrentReaderBarcode = task.ReaderBarcode; // 会自动显示出来

                if (this.Container.SpeakPatronName == true && results.Length >= 2)
                {
                    string strName = results[1];
                    this.Container.MainForm.Speak(strName);
                }



                // this.m_strCurrentBarcode = strBarcode;
                task.State = "finish";
                task.Color = "";
                // 兑现显示
                this.Container.DisplayTask("refresh", task);
                this.Container.SetColorList();
                // this.Container.CurrentReaderBarcodeChanged(this.CurrentReaderBarcode);  // 通知 读者记录已经成功装载
#if NO
                if (stop != null && stop.State != 0)
                    return true;
                return false;
#endif 
            return;
            ERROR1:
                task.State = "error";
                task.Color = "red";
                this.CurrentReaderBarcode = ""; // 及时清除上下文,避免后面错误借到先前的读者名下
                if (this.Container.IsCardMode == true)
                    this.Container.SetReaderCardString(task.ErrorInfo);
                else
                    this.Container.SetReaderTextString(task.ErrorInfo);
                // 兑现显示
                this.Container.DisplayTask("refresh", task);
                this.Container.SetColorList();
                this.Stopped = true;  // 全部任务停止处理。这是因为装载读者的操作比较重要,是后继操作的前提
#if NO
                if (stop != null && stop.State != 0)
                    return true;
                return false;
#endif
                return;
#if NO
            }
            finally
            {

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
#endif
        }