Exemple #1
0
        /*
发生未捕获的界面线程异常: 
Type: System.NullReferenceException
Message: 未将对象引用设置到对象的实例。
Stack:
在 dp2Circulation.BiblioStatisForm.RunScript(String strProjectName, String strProjectLocate, String strInitialParamString, String& strError, String& strWarning)
在 dp2Circulation.BiblioStatisForm.button_next_Click(Object sender, EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

         * */
        int RunScript(string strProjectName,
            string strProjectLocate,
            string strInitialParamString,
            out string strError,
            out string strWarning)
        {
            strError = "";
            strWarning = "";

            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在执行脚本 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            _dllPaths.Clear();
            _dllPaths.Add(strProjectLocate);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            try
            {
                int nRet = 0;
                strError = "";
                strWarning = "";

                this.DisposeBilbioStatisObject();
                // this.objStatis = null;

                this.AssemblyMain = null;
                MyFilterDocument filter = null;

                // 2009/11/5 
                // 防止以前残留的打开的文件依然没有关闭
                Global.ForceGarbageCollection();

                nRet = PrepareScript(strProjectName,
                    strProjectLocate,
                    out this.objStatis,
                    out filter,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                //
                if (filter != null)
                    this.AssemblyFilter = filter.Assembly;
                else
                    this.AssemblyFilter = null;

                this.MarcFilter = filter;
                //

                Debug.Assert(objStatis != null, "");

                objStatis.ProjectDir = strProjectLocate;
                objStatis.Console = this.Console;

                // 执行脚本的OnInitial()

                // 触发Script中OnInitial()代码
                // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    args.ParamString = strInitialParamString;
                    objStatis.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        goto END1;
                }

                // 触发Script中OnBegin()代码
                // OnBegin()中仍然有修改MainForm面板的自由
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        goto END1;
                }

                // 循环
                nRet = DoLoop(out strError,
                    out strWarning);
                if (nRet == -1)
                    goto ERROR1;

                if (nRet == 1)
                    goto END1;  // 实际上 SkipAll 是要执行 OnEnd() 的,而 Error 才是不执行 OnEnd()
            END1:
                // 触发Script的OnEnd()代码
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnEnd(this, args);
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        return -1;
                    }
                }
                return 0;
            ERROR1:
                return -1;
            }
            catch (Exception ex)
            {
                strError = "脚本执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                return -1;
            }
            finally
            {
                if (objStatis != null)
                    objStatis.FreeResources();

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

                this.AssemblyMain = null;

                EnableControls(true);

                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }
Exemple #2
0
        int RunScript(string strProjectName,
            string strProjectLocate,
            out string strError)
        {
            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在执行脚本 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            _dllPaths.Clear();
            _dllPaths.Add(strProjectLocate);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            try
            {

                int nRet = 0;
                strError = "";

                this.objStatis = null;
                this.AssemblyMain = null;

                // 2009/11/5
                // 防止以前残留的打开的文件依然没有关闭
                Global.ForceGarbageCollection();

                nRet = PrepareScript(strProjectName,
                    strProjectLocate,
                    out objStatis,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                objStatis.ProjectDir = strProjectLocate;
                objStatis.Console = this.Console;
                objStatis.InputFilename = this._openMarcFileDialog.FileName;

                // 执行脚本的OnInitial()

                // 触发Script中OnInitial()代码
                // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        goto END1;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                // 触发Script中OnBegin()代码
                // OnBegin()中仍然有修改MainForm面板的自由
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        goto END1;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                // 循环
                nRet = DoLoop(out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (nRet == 1)
                    goto END1;  // TODO: SkipAll如何执行? 是否连OnEnd也不执行了?

            END1:
                // 触发Script的OnEnd()代码
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnEnd(this, args);
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                return 0;

            ERROR1:
                return -1;
            }
            catch (Exception ex)
            {
                strError = "脚本执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                return -1;
            }
            finally
            {
                if (objStatis != null)
                    objStatis.FreeResources();

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

                this.AssemblyMain = null;

                EnableControls(true);
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }
Exemple #3
0
        /// <summary>
        /// 初始化。在统计方案执行的第一阶段被调用
        /// </summary>
        /// <param name="sender">事件触发者</param>
        /// <param name="e">事件参数</param>
        public virtual void OnInitial(object sender, StatisEventArgs e)
        {

        }
Exemple #4
0
        // 每一记录处理
        /// <summary>
        /// 处理一条记录。在统计方案执行中,第三阶段,针对每条记录被调用一次
        /// </summary>
        /// <param name="sender">事件触发者</param>
        /// <param name="e">事件参数</param>
        public virtual void OnRecord(object sender, StatisEventArgs e)
        {

        }
Exemple #5
0
 // 开始
 public virtual void OnBegin(object sender, StatisEventArgs e)
 {
 }
Exemple #6
0
        int RunScript(string strProjectName,
            string strProjectLocate,
            out string strError)
        {
            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在执行脚本 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            _dllPaths.Clear();
            _dllPaths.Add(strProjectLocate);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            try
            {
                int nRet = 0;
                strError = "";

                // Assembly assemblyMain = null;

                this.objStatis = null;
                this.AssemblyMain = null;

                // 2009/11/5 changed
                // 防止以前残留的打开的文件依然没有关闭
                Global.ForceGarbageCollection();

                /*
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
                */

                nRet = PrepareScript(strProjectName,
                    strProjectLocate,
                    // out assemblyMain,
                    out objStatis,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                /*
                 * 
                 * 
                string strDllName = "";
                nRet = PrepareScript(strProjectName,
                    strProjectLocate,
                    out strDllName,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                System.AppDomain NewAppDomain = System.AppDomain.CreateDomain("NewApplicationDomain");

                ObjectHandle h = NewAppDomain.CreateInstanceFrom(strDllName,
                    "scriptcode.MyStatis");
                objStatis = (Statis)h.Unwrap();

                m_strMainCsDllName = strDllName;

                // 为Statis派生类设置参数
                objStatis.OperLogStatisForm = this;
                objStatis.ProjectDir = strProjectLocate;
                 * */

                // this.AssemblyMain = assemblyMain;

                objStatis.ProjectDir = strProjectLocate;
                objStatis.Console = this.Console;
                objStatis.StartDate = this.dateControl_start.Value;
                objStatis.EndDate = this.dateControl_end.Value;

                // 执行脚本的OnInitial()

                // 触发Script中OnInitial()代码
                // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        goto END1;
                }

                // 触发Script中OnBegin()代码
                // OnBegin()中仍然有修改MainForm面板的自由
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        goto END1;
                }

                // 循环
                nRet = DoLoop(DoRecord, out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (nRet == 1)
                    goto END1;  // TODO: SkipAll如何执行? 是否连OnEnd也不执行了?

            END1:
                // 触发Script的OnEnd()代码
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnEnd(this, args);
                }

                return 0;

            ERROR1:
                return -1;

            }
            catch (Exception ex)
            {
                strError = "脚本执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                return -1;
            }
            finally
            {
                if (objStatis != null)
                    objStatis.FreeResources();

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();

                this.AssemblyMain = null;

                EnableControls(true);
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }
Exemple #7
0
        // 注意:上级函数RunScript()已经使用了BeginLoop()和EnableControls()
        // 对每个Iso2709Statis记录进行循环
        // return:
        //      0   普通返回
        //      1   要全部中断
        int DoLoop(out string strError)
        {
            strError = "";
            // int nRet = 0;
            // long lRet = 0;
            Encoding encoding = null;

            if (string.IsNullOrEmpty(this._openMarcFileDialog.EncodingName) == true)
            {
                strError = "尚未选定 ISO2709 文件的编码方式";
                return(-1);
            }

            if (StringUtil.IsNumber(this._openMarcFileDialog.EncodingName) == true)
            {
                encoding = Encoding.GetEncoding(Convert.ToInt32(this._openMarcFileDialog.EncodingName));
            }
            else
            {
                encoding = Encoding.GetEncoding(this._openMarcFileDialog.EncodingName);
            }

#if NO
            // 清除错误信息窗口中残余的内容
            if (this.ErrorInfoForm != null)
            {
                try
                {
                    this.ErrorInfoForm.HtmlString = "<pre>";
                }
                catch
                {
                }
            }
#endif
            ClearErrorInfoForm();

            string strInputFileName = "";

            try
            {
                strInputFileName = this._openMarcFileDialog.FileName;

                Stream file = null;

                try
                {
                    file = File.Open(strInputFileName,
                                     FileMode.Open,
                                     FileAccess.Read);
                }
                catch (Exception ex)
                {
                    strError = "打开文件 " + strInputFileName + " 失败: " + ex.Message;
                    return(-1);
                }

                this.progressBar_records.Minimum = 0;
                this.progressBar_records.Maximum = (int)file.Length;
                this.progressBar_records.Value   = 0;

                /*
                 * stop.OnStop += new StopEventHandler(this.DoStop);
                 * stop.Initial("正在获取ISO2709记录 ...");
                 * stop.BeginLoop();
                 *
                 * EnableControls(false);
                 * */

                try
                {
                    int nCount = 0;

                    for (int i = 0; ; i++)
                    {
                        Application.DoEvents(); // 出让界面控制权

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                DialogResult result = MessageBox.Show(this,
                                                                      "准备中断。\r\n\r\n确实要中断全部操作? (Yes 全部中断;No 中断循环,但是继续收尾处理;Cancel 放弃中断,继续操作)",
                                                                      "Iso2709StatisForm",
                                                                      MessageBoxButtons.YesNoCancel,
                                                                      MessageBoxIcon.Question,
                                                                      MessageBoxDefaultButton.Button3);

                                if (result == DialogResult.Yes)
                                {
                                    strError = "用户中断";
                                    return(-1);
                                }
                                if (result == DialogResult.No)
                                {
                                    return(0);   // 假装loop正常结束
                                }
                                stop.Continue(); // 继续循环
                            }
                        }


                        string strMARC = "";

                        // 从ISO2709文件中读入一条MARC记录
                        // return:
                        //	-2	MARC格式错
                        //	-1	出错
                        //	0	正确
                        //	1	结束(当前返回的记录有效)
                        //	2	结束(当前返回的记录无效)
                        int nRet = MarcUtil.ReadMarcRecord(file,
                                                           encoding,
                                                           true, // bRemoveEndCrLf,
                                                           true, // bForce,
                                                           out strMARC,
                                                           out strError);
                        if (nRet == -2 || nRet == -1)
                        {
                            DialogResult result = MessageBox.Show(this,
                                                                  "读入MARC记录(" + nCount.ToString() + ")出错: " + strError + "\r\n\r\n确实要中断当前批处理操作?",
                                                                  "Iso2709StatisForm",
                                                                  MessageBoxButtons.YesNo,
                                                                  MessageBoxIcon.Question,
                                                                  MessageBoxDefaultButton.Button2);
                            if (result == DialogResult.Yes)
                            {
                                break;
                            }
                            else
                            {
                                strError = "读入MARC记录(" + nCount.ToString() + ")出错: " + strError;
                                GetErrorInfoForm().WriteHtml(strError + "\r\n");
                                continue;
                            }
                        }

                        if (nRet != 0 && nRet != 1)
                        {
                            return(0);   // 结束
                        }
                        stop.SetMessage("正在获取第 " + (i + 1).ToString() + " 个 ISO2709 记录");
                        this.progressBar_records.Value = (int)file.Position;

                        // 跳过太短的记录
                        if (string.IsNullOrEmpty(strMARC) == true ||
                            strMARC.Length <= 24)
                        {
                            continue;
                        }

                        if (this._openMarcFileDialog.Mode880 == true &&
                            (this._openMarcFileDialog.MarcSyntax == "usmarc" || this._openMarcFileDialog.MarcSyntax == "<自动>"))
                        {
                            MarcRecord temp = new MarcRecord(strMARC);
                            MarcQuery.ToParallel(temp);
                            strMARC = temp.Text;
                        }

                        // 触发Script中OnRecord()代码
                        if (objStatis != null)
                        {
                            objStatis.MARC = strMARC;
                            objStatis.CurrentRecordIndex = i;

                            StatisEventArgs args = new StatisEventArgs();
                            objStatis.OnRecord(this, args);
                            if (args.Continue == ContinueType.SkipAll)
                            {
                                return(1);
                            }
                            if (args.Continue == ContinueType.Error)
                            {
                                strError = args.ParamString;
                                return(-1);
                            }
                        }

                        nCount++;
                    }

                    /*
                     * Global.WriteHtml(this.webBrowser_batchAddItemPrice,
                     *  "处理结束。共增补价格字符串 " + nCount.ToString() + " 个。\r\n");
                     * */

                    return(0);
                }
                finally
                {
                    /*
                     * EnableControls(true);
                     *
                     * stop.EndLoop();
                     * stop.OnStop -= new StopEventHandler(this.DoStop);
                     * stop.Initial("");
                     * */

                    if (file != null)
                    {
                        file.Close();
                    }
                }
            }
            finally
            {
            }

            // return 0;
        }
Exemple #8
0
        // 注意:上级函数RunScript()已经使用了BeginLoop()和EnableControls()
        // 对每个XML记录进行循环
        // return:
        //      0   普通返回
        //      1   要全部中断
        int DoLoop(out string strError)
        {
            strError = "";
            // int nRet = 0;
            // long lRet = 0;

#if NO
            // 清除错误信息窗口中残余的内容
            if (this.ErrorInfoForm != null)
            {
                try
                {
                    this.ErrorInfoForm.HtmlString = "<pre>";
                }
                catch
                {
                }
            }
#endif
            // 清除错误信息窗口中残余的内容
            ClearErrorInfoForm();

            string strInputFileName = "";

            try
            {
                strInputFileName = this.textBox_inputXmlFilename.Text;

                Stream file = null;

                try
                {
                    file = File.Open(strInputFileName,
                                     FileMode.Open,
                                     FileAccess.Read);
                }
                catch (Exception ex)
                {
                    strError = "打开文件 " + strInputFileName + " 失败: " + ex.Message;
                    return(-1);
                }

                XmlTextReader reader = new XmlTextReader(file);

                this.progressBar_records.Minimum = 0;
                this.progressBar_records.Maximum = (int)file.Length;
                this.progressBar_records.Value   = 0;

                /*
                 * stop.OnStop += new StopEventHandler(this.DoStop);
                 * stop.Initial("正在获取XML记录 ...");
                 * stop.BeginLoop();
                 *
                 * EnableControls(false);
                 * */

                bool bRet = false;

                while (true)
                {
                    bRet = reader.Read();
                    if (bRet == false)
                    {
                        strError = "没有根元素";
                        return(-1);
                    }
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        break;
                    }
                }

                try
                {
                    int nCount = 0;

                    for (int i = 0; ; i++)
                    {
                        Application.DoEvents(); // 出让界面控制权

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                DialogResult result = MessageBox.Show(this,
                                                                      "准备中断。\r\n\r\n确实要中断全部操作? (Yes 全部中断;No 中断循环,但是继续收尾处理;Cancel 放弃中断,继续操作)",
                                                                      "ReaderStatisForm",
                                                                      MessageBoxButtons.YesNoCancel,
                                                                      MessageBoxIcon.Question,
                                                                      MessageBoxDefaultButton.Button3);

                                if (result == DialogResult.Yes)
                                {
                                    strError = "用户中断";
                                    return(-1);
                                }
                                if (result == DialogResult.No)
                                {
                                    return(0);   // 假装loop正常结束
                                }
                                stop.Continue(); // 继续循环
                            }
                        }


                        while (true)
                        {
                            bRet = reader.Read();
                            if (bRet == false)
                            {
                                return(0);
                            }
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                break;
                            }
                        }

                        if (bRet == false)
                        {
                            return(0);   // 结束
                        }
                        string strXml = reader.ReadOuterXml();

                        stop.SetMessage("正在获取第 " + (i + 1).ToString() + " 个XML记录");
                        this.progressBar_records.Value = (int)file.Position;

                        // strXml中为XML记录
                        XmlDocument dom = new XmlDocument();
                        try
                        {
                            dom.LoadXml(strXml);
                        }
                        catch (Exception ex)
                        {
                            strError = "XML记录装入DOM发生错误: " + ex.Message;
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        // 触发Script中OnRecord()代码
                        if (objStatis != null)
                        {
                            objStatis.Xml                = strXml;
                            objStatis.RecordDom          = dom;
                            objStatis.CurrentRecordIndex = i;

                            StatisEventArgs args = new StatisEventArgs();
                            objStatis.OnRecord(this, args);
                            if (args.Continue == ContinueType.SkipAll)
                            {
                                return(1);
                            }
                        }

                        nCount++;
                    }

                    /*
                     * Global.WriteHtml(this.webBrowser_batchAddItemPrice,
                     *  "处理结束。共增补价格字符串 " + nCount.ToString() + " 个。\r\n");
                     * */
                }
                finally
                {
                    /*
                     * EnableControls(true);
                     *
                     * stop.EndLoop();
                     * stop.OnStop -= new StopEventHandler(this.DoStop);
                     * stop.Initial("");
                     * */

                    if (file != null)
                    {
                        file.Close();
                    }
                }
            }
            finally
            {
            }

            // return 0;
        }
Exemple #9
0
        // 任务1,每次记录处理
        int DoTask1Record(string strLogFileName,
string strXml,
bool bInCacheFile,
long lHint,
long lIndex,
long lAttachmentTotalLength,
object param,
out string strError)
        {
            strError = "";

            if (string.IsNullOrEmpty(strXml) == true)
                return 0;

            string strDate = "";
            int nRet = strLogFileName.IndexOf(".");
            if (nRet != -1)
                strDate = strLogFileName.Substring(0, nRet);
            else
                strDate = strLogFileName;

            DateTime currentDate = DateTimeUtil.Long8ToDateTime(strDate);
            // strXml中为日志记录
#if NO
            // 触发Script中OnRecord()代码
            if (objStatis != null)
            {
                objStatis.Xml = strXml;
                objStatis.CurrentDate = currentDate;
                objStatis.CurrentLogFileName = strLogFileName;
                objStatis.CurrentRecordIndex = lIndex;

                StatisEventArgs args = new StatisEventArgs();
                objStatis.OnRecord(this, args);
                if (args.Continue == ContinueType.SkipAll)
                    return 1;
            }
#endif

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strXml);
            }
            catch (Exception ex)
            {
                strError = "Load Xml to DOM error: " + ex.Message;
                return -1;
            }

            // this.WriteTextToConsole(this.CurrentLogFileName + ":" + this.CurrentRecordIndex.ToString() + "\r\n");

            string strOperation = DomUtil.GetElementText(dom.DocumentElement, "operation");

            if (strOperation != "borrow" && strOperation != "return")
                return 0;

            string strAction = DomUtil.GetElementText(dom.DocumentElement, "action");
            string strOperator = DomUtil.GetElementText(dom.DocumentElement, "operator");

            string strAccessClass = "";	// 索书号中的分类号
            string strBiblioRecPath = "";	// 书目记录路径

            string strLocation = "";    // 册馆藏地点

            XmlNode nodeItem = null;
            string strItemXml = DomUtil.GetElementText(dom.DocumentElement,
                    "itemRecord", out nodeItem);
            string strItemRecPath = "";
            if (nodeItem != null)
                strItemRecPath = DomUtil.GetAttr(nodeItem, "recPath");

            // 册记录相关的书目记录路径,这个后面统一提取,就不用日志记录中的数据了

            XmlNode nodeReader = null;
            string strReaderXml = DomUtil.GetElementText(dom.DocumentElement,
                    "readerRecord", out nodeReader);
            string strReaderRecPath = DomUtil.GetAttr(nodeReader, "recPath");
            string strReaderDbName = Global.GetDbName(strReaderRecPath);



            return 0;
        }
Exemple #10
0
 // 打印输出
 public virtual void OnPrint(object sender, StatisEventArgs e)
 {
 }
Exemple #11
0
        // 注意:上级函数RunScript()已经使用了BeginLoop()和EnableControls()
        // 对每个实体记录进行循环
        // return:
        //      0   普通返回
        //      1   要全部中断
        int DoLoop(out string strError)
        {
            strError = "";
            int nRet = 0;
            long lRet = 0;

            // List<string> LogFileNames = null;

            // 清除错误信息窗口中残余的内容
#if NO
            if (this.ErrorInfoForm != null)
            {
                try
                {
                    this.ErrorInfoForm.HtmlString = "<pre>";
                }
                catch
                {
                }
            }
#endif
            ClearErrorInfoForm();


            // 馆藏地点过滤列表
            string strLocationList = this.textBox_locationNames.Text.Trim();
            if (String.IsNullOrEmpty(strLocationList) == true)
                strLocationList = "*";

            string[] locations = strLocationList.Split(new char[] { ',' });

            StringMatchList location_matchlist = new StringMatchList(locations);

            // 实体类型过滤列表
            string strItemTypeList = this.textBox_itemTypes.Text.Trim();
            if (String.IsNullOrEmpty(strItemTypeList) == true)
                strItemTypeList = "*";

            string[] itemtypes = strItemTypeList.Split(new char[] { ',' });

            StringMatchList itemtype_matchlist = new StringMatchList(itemtypes);

            // 记录路径临时文件
            string strTempRecPathFilename = Path.GetTempFileName();

            string strInputFileName = "";   // 外部制定的输入文件,为条码号文件或者记录路径文件格式
            string strAccessPointName = "";

            try
            {

                if (this.InputStyle == ItemStatisInputStyle.BatchNo)
                {
                    nRet = SearchItemRecPath(
                        this.tabComboBox_inputBatchNo.Text,
                        strTempRecPathFilename,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    strInputFileName = strTempRecPathFilename;
                    strAccessPointName = "记录路径";
                }
                else if (this.InputStyle == ItemStatisInputStyle.BarcodeFile)
                {
                    Debug.Assert(this.DbType == "item", "");

                    strInputFileName = this.textBox_inputBarcodeFilename.Text;
                    strAccessPointName = "册条码";
                }
                else if (this.InputStyle == ItemStatisInputStyle.RecPathFile)
                {
                    strInputFileName = this.textBox_inputRecPathFilename.Text;
                    strAccessPointName = "记录路径";
                }
                else
                {
                    Debug.Assert(false, "");
                }

                StreamReader sr = null;

                try
                {
                    sr = new StreamReader(strInputFileName, Encoding.UTF8);
                }
                catch (Exception ex)
                {
                    strError = "打开文件 " + strInputFileName + " 失败: " + ex.Message;
                    return -1;
                }

                this.progressBar_records.Minimum = 0;
                this.progressBar_records.Maximum = (int)sr.BaseStream.Length;
                this.progressBar_records.Value = 0;

                /*
                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在获取册记录 ...");
                stop.BeginLoop();
                EnableControls(false);
                 * */


                try
                {
                    int nCount = 0;

                    for (int i = 0; ; i++)
                    {
                        Application.DoEvents();	// 出让界面控制权

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                DialogResult result = MessageBox.Show(this,
                                    "准备中断。\r\n\r\n确实要中断全部操作? (Yes 全部中断;No 中断循环,但是继续收尾处理;Cancel 放弃中断,继续操作)",
                                    this.DbType + "statisform",
                                    MessageBoxButtons.YesNoCancel,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button3);

                                if (result == DialogResult.Yes)
                                {
                                    strError = "用户中断";
                                    return -1;
                                }
                                if (result == DialogResult.No)
                                    return 0;   // 假装loop正常结束

                                stop.Continue(); // 继续循环
                            }
                        }

                        // string strItemBarcode = barcodes[i];
                        string strRecPathOrBarcode = sr.ReadLine();

                        if (strRecPathOrBarcode == null)
                            break;

                        if (String.IsNullOrEmpty(strRecPathOrBarcode) == true)
                            continue;

                        OutputDebugInfo("处理行" + (i + 1).ToString() + " '" + strRecPathOrBarcode + "'");

                        stop.SetMessage("正在获取第 " + (i + 1).ToString() + " 个" + this.DbTypeCaption + "记录," + strAccessPointName + "为 " + strRecPathOrBarcode);
                        this.progressBar_records.Value = (int)sr.BaseStream.Position;

                        // 获得册记录
                        string strOutputRecPath = "";
                        byte[] baTimestamp = null;


                        string strResult = "";

                        string strAccessPoint = "";
                        if (this.InputStyle == ItemStatisInputStyle.BatchNo)
                            strAccessPoint = "@path:" + strRecPathOrBarcode;
                        else if (this.InputStyle == ItemStatisInputStyle.RecPathFile)
                            strAccessPoint = "@path:" + strRecPathOrBarcode;
                        else if (this.InputStyle == ItemStatisInputStyle.BarcodeFile)
                            strAccessPoint = strRecPathOrBarcode;
                        else
                        {
                            Debug.Assert(false, "");
                        }

                        string strBiblio = "";
                        string strBiblioRecPath = "";
                        string strBiblioType = "recpath";
                        if (this.FirstGetBiblbioXml == true)
                            strBiblioType = "xml";

                        if (this.DbType == "item")
                        {
                            // Result.Value -1出错 0没有找到 1找到 >1命中多于1条
                            lRet = Channel.GetItemInfo(
                                stop,
                                strAccessPoint,
                                "xml", // strResultType,
                                out strResult,
                                out strOutputRecPath,
                                out baTimestamp,
                                strBiblioType,
                                out strBiblio,
                                out strBiblioRecPath,
                                out strError);
                        }
                        else if (this.DbType == "order")
                        {
                            // Result.Value -1出错 0没有找到 1找到 >1命中多于1条
                            lRet = Channel.GetOrderInfo(
                                stop,
                                strAccessPoint,
                                "xml", // strResultType,
                                out strResult,
                                out strOutputRecPath,
                                out baTimestamp,
                                strBiblioType,
                                out strBiblio,
                                out strBiblioRecPath,
                                out strError);
                        }
                        else if (this.DbType == "issue")
                        {
                            // Result.Value -1出错 0没有找到 1找到 >1命中多于1条
                            lRet = Channel.GetIssueInfo(
                                stop,
                                strAccessPoint,
                                "xml", // strResultType,
                                out strResult,
                                out strOutputRecPath,
                                out baTimestamp,
                                strBiblioType,
                                out strBiblio,
                                out strBiblioRecPath,
                                out strError);
                        }
                        else if (this.DbType == "comment")
                        {
                            // Result.Value -1出错 0没有找到 1找到 >1命中多于1条
                            lRet = Channel.GetCommentInfo(
                                stop,
                                strAccessPoint,
                                "xml", // strResultType,
                                out strResult,
                                out strOutputRecPath,
                                out baTimestamp,
                                strBiblioType,
                                out strBiblio,
                                out strBiblioRecPath,
                                out strError);
                        }
                        if (lRet == -1)
                        {
                            strError = "获得" + this.DbTypeCaption + "记录 " + strAccessPoint + " 时发生错误: " + strError;
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        if (lRet == 0)
                        {
                            strError = "" + strAccessPointName + " " + strRecPathOrBarcode + " 对应的XML数据没有找到。";
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        if (lRet > 1)
                        {
                            strError = "" + strAccessPointName + " " + strRecPathOrBarcode + " 对应数据多于一条。";
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        string strXml = "";

                        strXml = strResult;


                        // 看看是否在希望统计的范围内
                        XmlDocument dom = new XmlDocument();
                        try
                        {
                            dom.LoadXml(strXml);
                        }
                        catch (Exception ex)
                        {
                            strError = "册记录装入DOM发生错误: " + ex.Message;
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        if (this.DbType == "item")
                        {
                            // 按照馆藏地点筛选
                            if (this.textBox_locationNames.Text != ""
                                && this.textBox_locationNames.Text != "*")
                            {
                                // 注:空字符串或者"*"表示什么都满足。也就等于不使用此筛选项

                                string strLocation = DomUtil.GetElementText(dom.DocumentElement,
                                    "location");
                                if (location_matchlist.Match(strLocation) == false)
                                {
                                    OutputDebugInfo("馆藏地 '" + strLocation + "' 被筛选去除");
                                    continue;
                                }
                            }

                            // 按照册类型筛选
                            if (this.textBox_itemTypes.Text != ""
                                && this.textBox_itemTypes.Text != "*")
                            {
                                // 注:空字符串或者"*"表示什么都满足。也就等于不使用此筛选项

                                string strItemType = DomUtil.GetElementText(dom.DocumentElement,
                                    "bookType");
                                if (itemtype_matchlist.Match(strItemType) == false)
                                {
                                    OutputDebugInfo("册类型 '" + strItemType + "' 被筛选去除");
                                    continue;
                                }
                            }
                        }

                        // Debug.Assert(false, "");

                        // strXml中为册记录

                        // 触发Script中OnRecord()代码
                        if (objStatis != null)
                        {
                            objStatis.Xml = strXml;
                            objStatis.Timestamp = baTimestamp;
                            objStatis.ItemDom = dom;
                            objStatis.CurrentRecPath = strOutputRecPath;
                            objStatis.CurrentRecordIndex = i;
                            objStatis.CurrentBiblioRecPath = strBiblioRecPath;

                            if (this.FirstGetBiblbioXml == true)
                            {
                                objStatis.m_strBiblioXml = strBiblio;
                            }
                            else
                            {
                                objStatis.m_strBiblioXml = null;   // 迫使用到的时候重新获取
                            }

                            objStatis.m_biblioDom = null;   // 迫使用到的时候重新获取
                            objStatis.m_strMarcRecord = null;   // 迫使用到的时候重新获取
                            objStatis.m_strMarcSyntax = null;   // 迫使用到的时候重新获取


                            StatisEventArgs args = new StatisEventArgs();
                            objStatis.OnRecord(this, args);
                            if (args.Continue == ContinueType.SkipAll)
                                return 1;
                        }

                        nCount++;
                    }
                }
                finally
                {

                    /*
                    EnableControls(true);
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                     * */

                    if (sr != null)
                        sr.Close();
                }
            }
            finally
            {
                File.Delete(strTempRecPathFilename);
            }

            return 0;
        }
Exemple #12
0
        void menu_quickMarcQueryRecords_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选择要执行 C# 脚本的事项";
                goto ERROR1;
            }

            // 读者信息缓存
            // 如果已经初始化,则保持
            if (this.m_biblioTable == null)
                this.m_biblioTable = new Hashtable();

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = "请指定 C# 脚本文件";
            dlg.FileName = this.m_strUsedMarcQueryFilename;
            dlg.Filter = "C# 脚本文件 (*.cs)|*.cs|All files (*.*)|*.*";
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog() != DialogResult.OK)
                return;

            this.m_strUsedMarcQueryFilename = dlg.FileName;

            PatronHost host = null;
            Assembly assembly = null;

            nRet = PrepareMarcQuery(this.m_strUsedMarcQueryFilename,
                out assembly,
                out host,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            {
                host.MainForm = this.MainForm;
                host.UiForm = this;
                host.RecordPath = "";
                host.PatronDom = null;
                host.Changed = false;
                host.UiItem = null;

                StatisEventArgs args = new StatisEventArgs();
                host.OnInitial(this, args);
                if (args.Continue == ContinueType.SkipAll)
                    return;
                if (args.Continue == ContinueType.Error)
                {
                    strError = args.ParamString;
                    goto ERROR1;
                }
            }

            this.MainForm.OperHistory.AppendHtml("<div class='debug begin'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 开始执行脚本 " + dlg.FileName + "</div>");

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在针对读者记录执行 C# 脚本 ...");
            stop.BeginLoop();

            this.EnableControls(false);

            this.listView_records.Enabled = false;
            try
            {
                if (stop != null)
                    stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);

                host.CodeFileName = this.m_strUsedMarcQueryFilename;
                {
                    host.MainForm = this.MainForm;
                    host.RecordPath = "";
                    host.PatronDom = null;
                    host.Changed = false;
                    host.UiItem = null;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        return;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                List<ListViewItem> items = new List<ListViewItem>();
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    if (string.IsNullOrEmpty(item.Text) == true)
                        continue;

                    items.Add(item);
                }

                ListViewPatronLoader loader = new ListViewPatronLoader(this.Channel,
                    stop,
                    items,
                    this.m_biblioTable);
                loader.DbTypeCaption = this.DbTypeCaption;

                int i = 0;
                foreach (LoaderItem item in loader)
                {
                    Application.DoEvents();	// 出让界面控制权

                    if (stop != null
                        && stop.State != 0)
                    {
                        strError = "用户中断";
                        goto ERROR1;
                    }

                    stop.SetProgressValue(i);

                    BiblioInfo info = item.BiblioInfo;

                    this.MainForm.OperHistory.AppendHtml("<div class='debug recpath'>" + HttpUtility.HtmlEncode(info.RecPath) + "</div>");

                    host.MainForm = this.MainForm;
                    host.RecordPath = info.RecPath;
                    host.PatronDom = new XmlDocument();
                    host.PatronDom.LoadXml(info.OldXml);
                    host.Changed = false;
                    host.UiItem = item.ListViewItem;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnRecord(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        break;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }

                    if (host.Changed == true)
                    {
                        string strXml = host.PatronDom.OuterXml;
                        if (info != null)
                        {
                            if (string.IsNullOrEmpty(info.NewXml) == true)
                                this.m_nChangedCount++;
                            info.NewXml = strXml;
                        }

                        item.ListViewItem.BackColor = SystemColors.Info;
                        item.ListViewItem.ForeColor = SystemColors.InfoText;
                    }

                    // 显示为工作单形式
                    i++;
                }

                {
                    host.MainForm = this.MainForm;
                    host.RecordPath = "";
                    host.PatronDom = null;
                    host.Changed = false;
                    host.UiItem = null;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnEnd(this, args);
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }
            }
            catch (Exception ex)
            {
                strError = "执行 C# 脚本的过程中出现异常: " + ExceptionUtil.GetDebugText(ex);
                goto ERROR1;
            }
            finally
            {
                if (host != null)
                    host.FreeResources();

                this.listView_records.Enabled = true;

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;

                this.EnableControls(true);

                this.MainForm.OperHistory.AppendHtml("<div class='debug end'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 结束执行脚本 " + dlg.FileName + "</div>");
            }

            DoViewComment(false);
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Exemple #13
0
        // 注意:上级函数RunScript()已经使用了BeginLoop()和EnableControls()
        // 对每个书目记录进行循环
        // return:
        //      0   普通返回
        //      1   要全部中断
        int DoLoop(out string strError,
            out string strWarning)
        {
            strError = "";
            strWarning = "";

            int nRet = 0;
            long lRet = 0;

            bool bSyntaxWarned = false;
            bool bFilterWarned = false;

            // List<string> LogFileNames = null;

            // 清除错误信息窗口中残余的内容
            ClearErrorInfoForm();

            /*
            // 馆藏地点过滤列表
            string strLocationList = this.textBox_locationNames.Text;
            if (String.IsNullOrEmpty(strLocationList) == true)
                strLocationList = "*";

            string[] locations = strLocationList.Split(new char[] { ',' });

            StringMatchList location_matchlist = new StringMatchList(locations);

            // 读者类型过滤列表
            string strItemTypeList = this.textBox_itemTypes.Text;
            if (String.IsNullOrEmpty(strItemTypeList) == true)
                strItemTypeList = "*";

            string[] itemtypes = strItemTypeList.Split(new char[] { ',' });

            StringMatchList itemtype_matchlist = new StringMatchList(itemtypes);
             * */

            // 记录路径临时文件
            string strTempRecPathFilename = Path.GetTempFileName();

            string strInputFileName = "";   // 外部制定的输入文件,为条码号文件或者记录路径文件格式
            string strAccessPointName = "";

            try
            {

                if (this.InputStyle == BiblioStatisInputStyle.BatchNo)
                {
                    nRet = SearchBiblioRecPath(
                        this.tabComboBox_inputBatchNo.Text,
                        strTempRecPathFilename,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    strInputFileName = strTempRecPathFilename;
                    strAccessPointName = "记录路径";
                }
                else if (this.InputStyle == BiblioStatisInputStyle.RecPathFile)
                {
                    strInputFileName = this.textBox_inputRecPathFilename.Text;
                    strAccessPointName = "记录路径";
                }
                else if (this.InputStyle == BiblioStatisInputStyle.RecPaths)
                {
                    using (StreamWriter sw = new StreamWriter(strTempRecPathFilename, false, Encoding.UTF8))
                    {
                        sw.Write(this.textBox_inputStyle_recPaths.Text);
                    }

                    strInputFileName = strTempRecPathFilename;
                    strAccessPointName = "记录路径";
                }
                else
                {
                    Debug.Assert(false, "");
                }

                StreamReader sr = null;

                try
                {
                    sr = new StreamReader(strInputFileName, Encoding.UTF8);
                }
                catch (Exception ex)
                {
                    strError = "打开文件 " + strInputFileName + " 失败: " + ex.Message;
                    return -1;
                }

                this.progressBar_records.Minimum = 0;
                this.progressBar_records.Maximum = (int)sr.BaseStream.Length;
                this.progressBar_records.Value = 0;

                /*
                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在获取书目记录 ...");
                stop.BeginLoop();

                EnableControls(false);
                 * */

                try
                {
                    int nCount = 0;

                    for (int i = 0; ; i++)
                    {
                        Application.DoEvents();	// 出让界面控制权

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                DialogResult result = MessageBox.Show(this,
                                    "准备中断。\r\n\r\n确实要中断全部操作? (Yes 全部中断;No 中断循环,但是继续收尾处理;Cancel 放弃中断,继续操作)",
                                    "bibliostatisform",
                                    MessageBoxButtons.YesNoCancel,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button3);

                                if (result == DialogResult.Yes)
                                {
                                    strError = "用户中断";
                                    return -1;
                                }
                                if (result == DialogResult.No)
                                    return 0;   // 假装loop正常结束

                                stop.Continue(); // 继续循环
                            }
                        }

                        // string strItemBarcode = barcodes[i];
                        string strRecPath = sr.ReadLine();

                        if (strRecPath == null)
                            break;

                        strRecPath = strRecPath.Trim();
                        nRet = strRecPath.IndexOf("\t");
                        if (nRet != -1)
                            strRecPath = strRecPath.Substring(0, nRet).Trim();

                        if (String.IsNullOrEmpty(strRecPath) == true)
                            continue;

                        stop.SetMessage("正在获取第 " + (i + 1).ToString() + " 个书目记录," + strAccessPointName + "为 " + strRecPath);
                        this.progressBar_records.Value = (int)sr.BaseStream.Position;

                        // 获得书目记录
                        // string strOutputRecPath = "";
                        // byte[] baTimestamp = null;


                        string strAccessPoint = "";
                        if (this.InputStyle == BiblioStatisInputStyle.BatchNo)
                            strAccessPoint = strRecPath;
                        else if (this.InputStyle == BiblioStatisInputStyle.RecPathFile)
                            strAccessPoint = strRecPath;
                        else if (this.InputStyle == BiblioStatisInputStyle.RecPaths)
                            strAccessPoint = strRecPath;
                        else
                        {
                            Debug.Assert(false, "");
                        }

                        string strBiblio = "";
                        // string strBiblioRecPath = "";

#if NO
                        // Result.Value -1出错 0没有找到 1找到 >1命中多于1条
                        lRet = Channel.GetBiblioInfo(
                            stop,
                            strAccessPoint,
                            "", // strBiblioXml
                            "xml",   // strResultType
                            out strBiblio,
                            out strError);
#endif
                        string[] formats = new string[1];
                        formats[0] = "xml";
                        string[] results = null;
                        byte[] baTimestamp = null;
                        lRet = Channel.GetBiblioInfos(
                            stop,
                            strAccessPoint,
                            "",
                            formats,
                            out results,
                            out baTimestamp,
                            out strError);
                        if (lRet == -1)
                        {
                            strError = "获得书目记录 " + strAccessPoint + " 时发生错误: " + strError;
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        if (lRet == 0)
                        {
                            strError = "书目记录" + strAccessPointName + " " + strRecPath + " 对应的XML数据没有找到。";
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        if (lRet > 1)
                        {
                            strError = "书目记录" + strAccessPointName + " " + strRecPath + " 对应数据多于一条。";
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        if (results == null || results.Length == 0)
                        {
                            strError = "书目记录" + strAccessPointName + " " + strRecPath + " 获取时 results 出错。";
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }
                        strBiblio = results[0];
                        objStatis.Timestamp = baTimestamp;


                        string strXml = "";

                        strXml = strBiblio;


                        // 看看是否在希望统计的范围内
                        XmlDocument dom = new XmlDocument();
                        try
                        {
                            dom.LoadXml(strXml);
                        }
                        catch (Exception ex)
                        {
                            strError = "书目记录装入DOM发生错误: " + ex.Message;
                            continue;
                        }

                        /*
                        // 按照馆藏地点筛选
                        if (this.textBox_locationNames.Text != ""
                            && this.textBox_locationNames.Text != "*")
                        {
                            // 注:空字符串或者"*"表示什么都满足。也就等于不使用此筛选项

                            string strLocation = DomUtil.GetElementText(dom.DocumentElement,
                                "location");
                            if (location_matchlist.Match(strLocation) == false)
                                continue;
                        }

                        // 按照册类型筛选
                        if (this.textBox_itemTypes.Text != ""
                            && this.textBox_itemTypes.Text != "*")
                        {
                            // 注:空字符串或者"*"表示什么都满足。也就等于不使用此筛选项

                            string strItemType = DomUtil.GetElementText(dom.DocumentElement,
                                "bookType");
                            if (itemtype_matchlist.Match(strItemType) == false)
                                continue;
                        }
                         * */

                        // Debug.Assert(false, "");

                        // strXml中为书目记录
                        string strBiblioDbName = Global.GetDbName(strRecPath);

                        string strSyntax = this.MainForm.GetBiblioSyntax(strBiblioDbName);
                        if (String.IsNullOrEmpty(strSyntax) == true)
                            strSyntax = "unimarc";

                        bool bItemDomsCleared = false;

                        if (strSyntax == "usmarc" || strSyntax == "unimarc")
                        {
                            // 将XML书目记录转换为MARC格式
                            string strOutMarcSyntax = "";
                            string strMarc = "";

                            // 将MARCXML格式的xml记录转换为marc机内格式字符串
                            // parameters:
                            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                            nRet = MarcUtil.Xml2Marc(strXml,
                                true,   // 2013/1/12 修改为true
                                "", // strMarcSyntax
                                out strOutMarcSyntax,
                                out strMarc,
                                out strError);
                            if (nRet == -1)
                                return -1;

                            if (String.IsNullOrEmpty(strOutMarcSyntax) == false)
                            {
                                if (strOutMarcSyntax != strSyntax
                                    && bSyntaxWarned == false)
                                {
                                    strWarning += "书目记录 " + strRecPath + " 的syntax '" + strOutMarcSyntax + "' 和其所属数据库 '" + strBiblioDbName + "' 的定义syntax '" + strSyntax + "' 不一致\r\n";
                                    bSyntaxWarned = true;
                                }
                            }

                            objStatis.MarcRecord = strMarc;

                            if (this.MarcFilter != null)
                            {
                                // 触发Script中PreFilter()代码
                                if (objStatis != null)
                                {
                                    objStatis.Xml = strXml;
                                    objStatis.BiblioDom = dom;
                                    objStatis.CurrentDbSyntax = strSyntax;  // strOutputMarcSyntax?
                                    objStatis.CurrentRecPath = strRecPath;
                                    objStatis.CurrentRecordIndex = i;
                                    bItemDomsCleared = true;
                                    objStatis.ClearItemDoms();
                                    objStatis.ClearOrderDoms();
                                    objStatis.ClearIssueDoms();
                                    objStatis.ClearCommentDoms();

                                    StatisEventArgs args = new StatisEventArgs();
                                    objStatis.PreFilter(this, args);
                                    if (args.Continue == ContinueType.SkipAll)
                                        return 1;
                                }

                                // 触发filter中的Record相关动作
                                nRet = this.MarcFilter.DoRecord(
                                    null,
                                    objStatis.MarcRecord,
                                    strOutMarcSyntax,   // 2012/9/6
                                    i,
                                    out strError);
                                if (nRet == -1)
                                    return -1;
                            }
                        }
                        else
                        {
                            objStatis.MarcRecord = "";

                            if (this.MarcFilter != null
                                && bFilterWarned == false)
                            {
                                // TODO: 是否需要警告?因为配置了filter, 但是因为所涉及的库不是MARC格式,没有办法应用
                                // 可以最后集中警告一次
                                strWarning += "当前统计方案中配置了MarcFilter,但是因为数据库 '" + strBiblioDbName + "' (可能不仅限于这一个数据库)的定义syntax '" + strSyntax + "' 不是MARC类格式,所以统计过程中至少对这个库无法启用MarcFilter功能。\r\n";
                                bFilterWarned = true;
                            }
                        }

                        // 触发Script中OnRecord()代码
                        if (objStatis != null)
                        {
                            objStatis.Xml = strXml;
                            objStatis.BiblioDom = dom;
                            objStatis.CurrentDbSyntax = strSyntax;  // strOutputMarcSyntax?
                            objStatis.CurrentRecPath = strRecPath;
                            objStatis.CurrentRecordIndex = i;
                            if (bItemDomsCleared == false)
                            {
                                objStatis.ClearItemDoms();
                                objStatis.ClearOrderDoms();
                                objStatis.ClearIssueDoms();
                                objStatis.ClearCommentDoms();
                                bItemDomsCleared = true;
                            }

                            StatisEventArgs args = new StatisEventArgs();
                            objStatis.OnRecord(this, args);
                            if (args.Continue == ContinueType.SkipAll)
                                return 1;
                        }

                        nCount++;
                    }

                }
                finally
                {
                    /*
                    EnableControls(true);

                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                     * */

                    if (sr != null)
                        sr.Close();
                }
            }
            finally
            {
                File.Delete(strTempRecPathFilename);
            }

            return 0;
        }
Exemple #14
0
        // 注意:上级函数RunScript()已经使用了BeginLoop()和EnableControls()
        // 对每个Iso2709Statis记录进行循环
        // return:
        //      0   普通返回
        //      1   要全部中断
        int DoLoop(out string strError)
        {
            strError = "";
            // int nRet = 0;
            // long lRet = 0;
            Encoding encoding = null;

            if (string.IsNullOrEmpty(this._openMarcFileDialog.EncodingName) == true)
            {
                strError = "尚未选定 ISO2709 文件的编码方式";
                return -1;
            }

            if (StringUtil.IsNumber(this._openMarcFileDialog.EncodingName) == true)
                encoding = Encoding.GetEncoding(Convert.ToInt32(this._openMarcFileDialog.EncodingName));
            else
                encoding = Encoding.GetEncoding(this._openMarcFileDialog.EncodingName);

#if NO
            // 清除错误信息窗口中残余的内容
            if (this.ErrorInfoForm != null)
            {
                try
                {
                    this.ErrorInfoForm.HtmlString = "<pre>";
                }
                catch
                {
                }
            }
#endif
            ClearErrorInfoForm();


            string strInputFileName = "";

            try
            {
                strInputFileName = this._openMarcFileDialog.FileName;

                Stream file = null;

                try
                {
                    file = File.Open(strInputFileName,
                        FileMode.Open,
                        FileAccess.Read);
                }
                catch (Exception ex)
                {
                    strError = "打开文件 " + strInputFileName + " 失败: " + ex.Message;
                    return -1;
                }

                this.progressBar_records.Minimum = 0;
                this.progressBar_records.Maximum = (int)file.Length;
                this.progressBar_records.Value = 0;

                /*
                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在获取ISO2709记录 ...");
                stop.BeginLoop();

                EnableControls(false);
                 * */

                try
                {
                    int nCount = 0;

                    for (int i = 0; ; i++)
                    {
                        Application.DoEvents();	// 出让界面控制权

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                DialogResult result = MessageBox.Show(this,
                                    "准备中断。\r\n\r\n确实要中断全部操作? (Yes 全部中断;No 中断循环,但是继续收尾处理;Cancel 放弃中断,继续操作)",
                                    "Iso2709StatisForm",
                                    MessageBoxButtons.YesNoCancel,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button3);

                                if (result == DialogResult.Yes)
                                {
                                    strError = "用户中断";
                                    return -1;
                                }
                                if (result == DialogResult.No)
                                    return 0;   // 假装loop正常结束

                                stop.Continue(); // 继续循环
                            }
                        }


                        string strMARC = "";

                        // 从ISO2709文件中读入一条MARC记录
                        // return:
                        //	-2	MARC格式错
                        //	-1	出错
                        //	0	正确
                        //	1	结束(当前返回的记录有效)
                        //	2	结束(当前返回的记录无效)
                        int nRet = MarcUtil.ReadMarcRecord(file,
                            encoding,
                            true,	// bRemoveEndCrLf,
                            true,	// bForce,
                            out strMARC,
                            out strError);
                        if (nRet == -2 || nRet == -1)
                        {
                            DialogResult result = MessageBox.Show(this,
                                "读入MARC记录(" + nCount.ToString() + ")出错: " + strError + "\r\n\r\n确实要中断当前批处理操作?",
                                "Iso2709StatisForm",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2);
                            if (result == DialogResult.Yes)
                            {
                                break;
                            }
                            else
                            {
                                strError = "读入MARC记录(" + nCount.ToString() + ")出错: " + strError;
                                GetErrorInfoForm().WriteHtml(strError + "\r\n");
                                continue;
                            }
                        }

                        if (nRet != 0 && nRet != 1)
                            return 0;	// 结束

                        stop.SetMessage("正在获取第 " + (i + 1).ToString() + " 个 ISO2709 记录");
                        this.progressBar_records.Value = (int)file.Position;

                        // 跳过太短的记录
                        if (string.IsNullOrEmpty(strMARC) == true
                            || strMARC.Length <= 24)
                            continue;

                        if (this._openMarcFileDialog.Mode880 == true
                            && (this._openMarcFileDialog.MarcSyntax == "usmarc" || this._openMarcFileDialog.MarcSyntax == "<自动>"))
                        {
                            MarcRecord temp = new MarcRecord(strMARC);
                            MarcQuery.ToParallel(temp);
                            strMARC = temp.Text;
                        }

                        // 触发Script中OnRecord()代码
                        if (objStatis != null)
                        {
                            objStatis.MARC = strMARC;
                            objStatis.CurrentRecordIndex = i;

                            StatisEventArgs args = new StatisEventArgs();
                            objStatis.OnRecord(this, args);
                            if (args.Continue == ContinueType.SkipAll)
                                return 1;
                            if (args.Continue == ContinueType.Error)
                            {
                                strError = args.ParamString;
                                return -1;
                            }
                        }

                        nCount++;
                    }

                    /*
                    Global.WriteHtml(this.webBrowser_batchAddItemPrice,
                        "处理结束。共增补价格字符串 " + nCount.ToString() + " 个。\r\n");
                     * */

                    return 0;
                }
                finally
                {
                    /*
                    EnableControls(true);

                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                     * */

                    if (file != null)
                        file.Close();
                }
            }
            finally
            {
            }

            // return 0;
        }
Exemple #15
0
        public override int RunScript(string strProjectName,
                                      string strProjectLocate,
                                      string strInitialParamString,
                                      out string strError,
                                      out string strWarning)
        {
            strWarning = "";

            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在执行脚本 ...");
            stop.BeginLoop();

            this.Update();
            Program.MainForm.Update();

            _dllPaths.Clear();
            _dllPaths.Add(strProjectLocate);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            try
            {
                int nRet = 0;
                strError = "";

                // Assembly assemblyMain = null;

                this.objStatis    = null;
                this.AssemblyMain = null;

                // 2009/11/5 changed
                // 防止以前残留的打开的文件依然没有关闭
                Global.ForceGarbageCollection();

                /*
                 * AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
                 * AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
                 */

                nRet = PrepareScript(strProjectName,
                                     strProjectLocate,
                                     // out assemblyMain,
                                     out objStatis,
                                     out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                if (strInitialParamString == "test_compile")
                {
                    return(0);
                }


                /*
                 *
                 *
                 * string strDllName = "";
                 * nRet = PrepareScript(strProjectName,
                 *  strProjectLocate,
                 *  out strDllName,
                 *  out strError);
                 * if (nRet == -1)
                 *  goto ERROR1;
                 *
                 * System.AppDomain NewAppDomain = System.AppDomain.CreateDomain("NewApplicationDomain");
                 *
                 * ObjectHandle h = NewAppDomain.CreateInstanceFrom(strDllName,
                 *  "scriptcode.MyStatis");
                 * objStatis = (Statis)h.Unwrap();
                 *
                 * m_strMainCsDllName = strDllName;
                 *
                 * // 为Statis派生类设置参数
                 * objStatis.OperLogStatisForm = this;
                 * objStatis.ProjectDir = strProjectLocate;
                 * */

                // this.AssemblyMain = assemblyMain;

                objStatis.ProjectDir = strProjectLocate;
                objStatis.Console    = this.Console;
                objStatis.StartDate  = this.dateControl_start.Value;
                objStatis.EndDate    = this.dateControl_end.Value;

                // 执行脚本的OnInitial()

                // 触发Script中OnInitial()代码
                // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                    {
                        goto END1;
                    }
                }

                // 触发Script中OnBegin()代码
                // OnBegin()中仍然有修改MainForm面板的自由
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                    {
                        goto END1;
                    }
                }

                // 循环
                nRet = DoLoop(DoRecord, out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                if (nRet == 1)
                {
                    goto END1;  // TODO: SkipAll如何执行? 是否连OnEnd也不执行了?
                }
END1:
                // 触发Script的OnEnd()代码
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnEnd(this, args);
                }

                return(0);

ERROR1:
                return(-1);
            }
            catch (Exception ex)
            {
                strError = "脚本执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                if (objStatis != null)
                {
                    objStatis.FreeResources();
                }

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();

                this.AssemblyMain = null;

                EnableControls(true);
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }
Exemple #16
0
        int RunScript(string strProjectName,
                      string strProjectLocate,
                      out string strError)
        {
            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在执行脚本 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            _dllPaths.Clear();
            _dllPaths.Add(strProjectLocate);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            try
            {
                int nRet = 0;
                strError = "";

                this.objStatis    = null;
                this.AssemblyMain = null;

                // 2009/11/5
                // 防止以前残留的打开的文件依然没有关闭
                Global.ForceGarbageCollection();

                nRet = PrepareScript(strProjectName,
                                     strProjectLocate,
                                     out objStatis,
                                     out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                objStatis.ProjectDir    = strProjectLocate;
                objStatis.Console       = this.Console;
                objStatis.InputFilename = this.textBox_inputXmlFilename.Text;


                // 执行脚本的OnInitial()

                // 触发Script中OnInitial()代码
                // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                    {
                        goto END1;
                    }
                }


                // 触发Script中OnBegin()代码
                // OnBegin()中仍然有修改MainForm面板的自由
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                    {
                        goto END1;
                    }
                }

                // 循环
                nRet = DoLoop(out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                if (nRet == 1)
                {
                    goto END1;  // TODO: SkipAll如何执行? 是否连OnEnd也不执行了?
                }
END1:
                // 触发Script的OnEnd()代码
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnEnd(this, args);
                }

                return(0);

ERROR1:
                return(-1);
            }
            catch (Exception ex)
            {
                strError = "脚本执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                if (objStatis != null)
                {
                    objStatis.FreeResources();
                }

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

                this.AssemblyMain = null;

                EnableControls(true);
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }
Exemple #17
0
        // 注意:上级函数RunScript()已经使用了BeginLoop()和EnableControls()
        // 对每个XML记录进行循环
        // return:
        //      0   普通返回
        //      1   要全部中断
        int DoLoop(out string strError)
        {
            strError = "";
            // int nRet = 0;
            // long lRet = 0;

#if NO
            // 清除错误信息窗口中残余的内容
            if (this.ErrorInfoForm != null)
            {
                try
                {
                    this.ErrorInfoForm.HtmlString = "<pre>";
                }
                catch
                {
                }
            }
#endif
            // 清除错误信息窗口中残余的内容
            ClearErrorInfoForm();

            string strInputFileName = "";

            try
            {
                strInputFileName = this.textBox_inputXmlFilename.Text;

                Stream file = null;

                try
                {
                    file = File.Open(strInputFileName,
                        FileMode.Open,
                        FileAccess.Read);
                }
                catch (Exception ex)
                {
                    strError = "打开文件 " + strInputFileName + " 失败: " + ex.Message;
                    return -1;
                }

                XmlTextReader reader = new XmlTextReader(file);

                this.progressBar_records.Minimum = 0;
                this.progressBar_records.Maximum = (int)file.Length;
                this.progressBar_records.Value = 0;

                /*
                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在获取XML记录 ...");
                stop.BeginLoop();

                EnableControls(false);
                 * */

                bool bRet = false;

                while (true)
                {
                    bRet = reader.Read();
                    if (bRet == false)
                    {
                        strError = "没有根元素";
                        return -1;
                    }
                    if (reader.NodeType == XmlNodeType.Element)
                        break;
                }

                try
                {
                    int nCount = 0;

                    for (int i = 0; ; i++)
                    {
                        Application.DoEvents();	// 出让界面控制权

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                DialogResult result = MessageBox.Show(this,
                                    "准备中断。\r\n\r\n确实要中断全部操作? (Yes 全部中断;No 中断循环,但是继续收尾处理;Cancel 放弃中断,继续操作)",
                                    "ReaderStatisForm",
                                    MessageBoxButtons.YesNoCancel,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button3);

                                if (result == DialogResult.Yes)
                                {
                                    strError = "用户中断";
                                    return -1;
                                }
                                if (result == DialogResult.No)
                                    return 0;   // 假装loop正常结束

                                stop.Continue(); // 继续循环
                            }
                        }


                        while (true)
                        {
                            bRet = reader.Read();
                            if (bRet == false)
                                return 0;
                            if (reader.NodeType == XmlNodeType.Element)
                                break;
                        }

                        if (bRet == false)
                            return 0;	// 结束

                        string strXml = reader.ReadOuterXml();

                        stop.SetMessage("正在获取第 " + (i + 1).ToString() + " 个XML记录");
                        this.progressBar_records.Value = (int)file.Position;

                        // strXml中为XML记录
                        XmlDocument dom = new XmlDocument();
                        try
                        {
                            dom.LoadXml(strXml);
                        }
                        catch (Exception ex)
                        {
                            strError = "XML记录装入DOM发生错误: " + ex.Message;
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                            continue;
                        }

                        // 触发Script中OnRecord()代码
                        if (objStatis != null)
                        {
                            objStatis.Xml = strXml;
                            objStatis.RecordDom = dom;
                            objStatis.CurrentRecordIndex = i;

                            StatisEventArgs args = new StatisEventArgs();
                            objStatis.OnRecord(this, args);
                            if (args.Continue == ContinueType.SkipAll)
                                return 1;
                        }

                        nCount++;
                    }

                    /*
                    Global.WriteHtml(this.webBrowser_batchAddItemPrice,
                        "处理结束。共增补价格字符串 " + nCount.ToString() + " 个。\r\n");
                     * */


                }
                finally
                {
                    /*
                    EnableControls(true);

                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                     * */

                    if (file != null)
                        file.Close();
                }
            }
            finally
            {
            }

            // return 0;
        }
Exemple #18
0
 // 初始化
 public virtual void OnInitial(object sender, StatisEventArgs e)
 {
 }
Exemple #19
0
 // 每一记录,在触发MARCFilter之前
 /// <summary>
 /// 处理一条记录之前。在统计方案执行中,第三阶段,针对每条记录被调用一次,在 OnRecord() 之前触发
 /// </summary>
 /// <param name="sender">事件触发者</param>
 /// <param name="e">事件参数</param>
 public virtual void PreFilter(object sender, StatisEventArgs e)
 {
 }
Exemple #20
0
        private void button_print_runScript_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = "请指定 C# 脚本文件";
            dlg.FileName = this.m_strUsedScriptFilename;
            dlg.Filter = "C# 脚本文件 (*.cs)|*.cs|All files (*.*)|*.*";
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog() != DialogResult.OK)
                return;

            this.m_strUsedScriptFilename = dlg.FileName;

            AccountBookHost host = null;
            Assembly assembly = null;

            nRet = PrepareScript(this.m_strUsedScriptFilename,
                out assembly,
                out host,
                out strError);
            if (nRet == -1)
                goto ERROR1;



            this.MainForm.OperHistory.AppendHtml("<div class='debug begin'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 开始执行脚本 " + dlg.FileName + "</div>");

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在针对浏览行 C# 脚本 ...");
            stop.BeginLoop();

            this.EnableControls(false);

            this.listView_in.Enabled = false;
            try
            {
                {
                    host.AccountBookForm = this;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        return;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                if (stop != null)
                    stop.SetProgressRange(0, this.listView_in.Items.Count);

                {
                    host.AccountBookForm = this;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        return;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                int i = 0; 
                foreach (ListViewItem item in this.listView_in.Items)
                {
                    Application.DoEvents();	// 出让界面控制权

                    if (stop != null
                        && stop.State != 0)
                    {
                        strError = "用户中断";
                        goto ERROR1;
                    }

                    stop.SetProgressValue(i);


                    this.MainForm.OperHistory.AppendHtml("<div class='debug recpath'>" + HttpUtility.HtmlEncode((i + 1).ToString()) + "</div>");

                    host.AccountBookForm = this;
                    host.ListViewItem = item;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnRecord(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        break;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }

                    i++;
                }

                {
                    host.AccountBookForm = this;
                    host.ListViewItem = null;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnEnd(this, args);
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }
            }
            finally
            {
                if (host != null)
                    host.FreeResources();

                this.listView_in.Enabled = true;

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;

                this.EnableControls(true);

                this.MainForm.OperHistory.AppendHtml("<div class='debug end'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 结束执行脚本 " + dlg.FileName + "</div>");
            }

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Exemple #21
0
 /// <summary>
 /// 处理一条记录。在统计方案执行中,第三阶段,针对每条记录被调用一次
 /// </summary>
 /// <param name="sender">事件触发者</param>
 /// <param name="e">事件参数</param>
 public virtual void OnRecord(object sender, StatisEventArgs e)
 {
 }
Exemple #22
0
        int DoRecord(string strLogFileName,
    string strXml,
    bool bInCacheFile,
    long lHint,
    long lIndex,
    long lAttachmentTotalLength,
    object param,
    out string strError)
        {
            strError = "";

            if (string.IsNullOrEmpty(strXml) == true)
                return 0;

            string strDate = "";
            int nRet = strLogFileName.IndexOf(".");
            if (nRet != -1)
                strDate = strLogFileName.Substring(0, nRet);
            else
                strDate = strLogFileName;

            DateTime currentDate = DateTimeUtil.Long8ToDateTime(strDate);
            // strXml中为日志记录

            // 触发Script中OnRecord()代码
            if (objStatis != null)
            {
                objStatis.Xml = strXml;
                objStatis.CurrentDate = currentDate;
                objStatis.CurrentLogFileName = strLogFileName;
                objStatis.CurrentRecordIndex = lIndex;

                StatisEventArgs args = new StatisEventArgs();
                objStatis.OnRecord(this, args);
                if (args.Continue == ContinueType.SkipAll)
                    return 1;
            }

            return 0;
        }
Exemple #23
0
        // 每一记录,在触发MARCFilter之前
        /// <summary>
        /// 处理一条记录之前。在统计方案执行中,第三阶段,针对每条记录被调用一次,在 OnRecord() 之前触发
        /// </summary>
        /// <param name="sender">事件触发者</param>
        /// <param name="e">事件参数</param>
        public virtual void PreFilter(object sender, StatisEventArgs e)
        {

        }
Exemple #24
0
        // 开始
        /// <summary>
        /// 开始。在统计方案执行的第二阶段被调用
        /// </summary>
        /// <param name="sender">事件触发者</param>
        /// <param name="e">事件参数</param>
        public virtual void OnBegin(object sender, StatisEventArgs e)
        {

        }
Exemple #25
0
        void menu_quickMarcQueryRecords_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选择要执行 MarcQuery 脚本的事项";
                goto ERROR1;
            }

            // 书目信息缓存
            // 如果已经初始化,则保持
            if (this.m_biblioTable == null)
                this.m_biblioTable = new Hashtable();

            // this.m_biblioTable.Clear();

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = "请指定 MarcQuery 脚本文件";
            dlg.FileName = this.m_strUsedMarcQueryFilename;
            dlg.Filter = "MarcQuery 脚本文件 (*.cs)|*.cs|All files (*.*)|*.*";
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog() != DialogResult.OK)
                return;

            this.m_strUsedMarcQueryFilename = dlg.FileName;

            MarcQueryHost host = null;
            Assembly assembly = null;

            nRet = PrepareMarcQuery(this.m_strUsedMarcQueryFilename,
                out assembly,
                out host,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            host.CodeFileName = this.m_strUsedMarcQueryFilename;
            {
                host.MainForm = this.MainForm;
                host.UiForm = this;
                host.RecordPath = "";
                host.MarcRecord = null;
                host.MarcSyntax = "";
                host.Changed = false;
                host.UiItem = null;

                StatisEventArgs args = new StatisEventArgs();
                host.OnInitial(this, args);
                if (args.Continue == ContinueType.SkipAll)
                    return;
                if (args.Continue == ContinueType.Error)
                {
                    strError = args.ParamString;
                    goto ERROR1;
                }
            }

            this.MainForm.OperHistory.AppendHtml("<div class='debug begin'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 开始执行脚本 " + dlg.FileName + "</div>");

            LibraryChannel channel = this.GetChannel();

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在针对书目记录执行 MarcQuery 脚本 ...");
            stop.BeginLoop();

            this.EnableControls(false);

            this.listView_records.Enabled = false;
            try
            {
                if (stop != null)
                    stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);

                {
                    host.MainForm = this.MainForm;
                    host.RecordPath = "";
                    host.MarcRecord = null;
                    host.MarcSyntax = "";
                    host.Changed = false;
                    host.UiItem = null;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        return;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                List<ListViewItem> items = new List<ListViewItem>();
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    if (string.IsNullOrEmpty(item.Text) == true)
                        continue;

                    items.Add(item);
                }

                bool bOldSource = true; // 是否要从 OldXml 开始做起

                int nChangeCount = this.GetItemsChangeCount(items);
                if (nChangeCount > 0)
                {
                    bool bHideMessageBox = true;
                    DialogResult result = MessageDialog.Show(this,
                        "当前选定的 " + items.Count.ToString() + " 个事项中有 " + nChangeCount + " 项修改尚未保存。\r\n\r\n请问如何进行修改? \r\n\r\n(重新修改) 重新进行修改,忽略以前内存中的修改; \r\n(继续修改) 以上次的修改为基础继续修改; \r\n(放弃) 放弃整个操作",
    MessageBoxButtons.YesNoCancel,
    MessageBoxDefaultButton.Button1,
    null,
    ref bHideMessageBox,
    new string[] { "重新修改", "继续修改", "放弃" });
                    if (result == DialogResult.Cancel)
                    {
                        // strError = "放弃";
                        return;
                    }
                    if (result == DialogResult.No)
                    {
                        bOldSource = false;
                    }
                }

                ListViewBiblioLoader loader = new ListViewBiblioLoader(channel, // this.Channel,
                    stop,
                    items,
                    this.m_biblioTable);
                loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
                loader.Prompt += new MessagePromptEventHandler(loader_Prompt);

                int i = 0;
                foreach (LoaderItem item in loader)
                {
                    Application.DoEvents();	// 出让界面控制权

                    if (stop != null
                        && stop.State != 0)
                    {
                        strError = "用户中断";
                        goto ERROR1;
                    }

                    stop.SetProgressValue(i);

                    BiblioInfo info = item.BiblioInfo;

                    string strXml = "";
                    if (bOldSource == true)
                    {
                        strXml = info.OldXml;
                        // 放弃上一次的修改
                        if (string.IsNullOrEmpty(info.NewXml) == false)
                        {
                            info.NewXml = "";
                            this.m_nChangedCount--;
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(info.NewXml) == false)
                            strXml = info.NewXml;
                        else
                            strXml = info.OldXml;
                    }

                    string strMARC = "";
                    string strMarcSyntax = "";
                    // 将XML格式转换为MARC格式
                    // 自动从数据记录中获得MARC语法
                    nRet = MarcUtil.Xml2Marc(strXml,    // info.OldXml,
                        true,
                        null,
                        out strMarcSyntax,
                        out strMARC,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "XML转换到MARC记录时出错: " + strError;
                        goto ERROR1;
                    }

                    this.MainForm.OperHistory.AppendHtml("<div class='debug recpath'>" + HttpUtility.HtmlEncode(info.RecPath) + "</div>");

                    host.MainForm = this.MainForm;
                    host.RecordPath = info.RecPath;
                    host.MarcRecord = new MarcRecord(strMARC);
                    host.MarcSyntax = strMarcSyntax;
                    host.Changed = false;
                    host.UiItem = item.ListViewItem;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnRecord(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                        break;
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }

                    if (host.Changed == true)
                    {
                        strXml = info.OldXml;
                        nRet = MarcUtil.Marc2XmlEx(host.MarcRecord.Text,
                            strMarcSyntax,
                            ref strXml,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;

                        if (info != null)
                        {
                            if (string.IsNullOrEmpty(info.NewXml) == true)
                                this.m_nChangedCount++;
                            info.NewXml = strXml;
                        }

                        item.ListViewItem.BackColor = SystemColors.Info;
                        item.ListViewItem.ForeColor = SystemColors.InfoText;
                    }

                    // 显示为工作单形式
                    i++;
                }

                {
                    host.MainForm = this.MainForm;
                    host.RecordPath = "";
                    host.MarcRecord = null;
                    host.MarcSyntax = "";
                    host.Changed = false;
                    host.UiItem = null;

                    StatisEventArgs args = new StatisEventArgs();
                    host.OnEnd(this, args);
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }
            }
            catch (Exception ex)
            {

                strError = "执行 MarcQuery 脚本的过程中出现异常: " + ExceptionUtil.GetDebugText(ex);
                goto ERROR1;
            }
            finally
            {
                if (host != null)
                    host.FreeResources();

                this.listView_records.Enabled = true;

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;

                this.ReturnChannel(channel);

                this.EnableControls(true);

                this.MainForm.OperHistory.AppendHtml("<div class='debug end'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 结束执行脚本 " + dlg.FileName + "</div>");
            }

            RefreshPropertyView(false);
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Exemple #26
0
        // 打印输出
        /// <summary>
        /// 打印输出。在统计方案执行结束后,需要打印的时候被调用
        /// </summary>
        /// <param name="sender">事件触发者</param>
        /// <param name="e">事件参数</param>
        public virtual void OnPrint(object sender, StatisEventArgs e)
        {

        }
Exemple #27
0
        // 任务1,每次记录处理
        int DoTask1Record(string strLogFileName,
                          string strXml,
                          bool bInCacheFile,
                          long lHint,
                          long lIndex,
                          long lAttachmentTotalLength,
                          object param,
                          out string strError)
        {
            strError = "";

            if (string.IsNullOrEmpty(strXml) == true)
            {
                return(0);
            }

            string strDate = "";
            int    nRet    = strLogFileName.IndexOf(".");

            if (nRet != -1)
            {
                strDate = strLogFileName.Substring(0, nRet);
            }
            else
            {
                strDate = strLogFileName;
            }

            DateTime currentDate = DateTimeUtil.Long8ToDateTime(strDate);

            // strXml中为日志记录
#if NO
            // 触发Script中OnRecord()代码
            if (objStatis != null)
            {
                objStatis.Xml                = strXml;
                objStatis.CurrentDate        = currentDate;
                objStatis.CurrentLogFileName = strLogFileName;
                objStatis.CurrentRecordIndex = lIndex;

                StatisEventArgs args = new StatisEventArgs();
                objStatis.OnRecord(this, args);
                if (args.Continue == ContinueType.SkipAll)
                {
                    return(1);
                }
            }
#endif

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strXml);
            }
            catch (Exception ex)
            {
                strError = "Load Xml to DOM error: " + ex.Message;
                return(-1);
            }

            // this.WriteTextToConsole(this.CurrentLogFileName + ":" + this.CurrentRecordIndex.ToString() + "\r\n");

            string strOperation = DomUtil.GetElementText(dom.DocumentElement, "operation");

            if (strOperation != "borrow" && strOperation != "return")
            {
                return(0);
            }

            string strAction   = DomUtil.GetElementText(dom.DocumentElement, "action");
            string strOperator = DomUtil.GetElementText(dom.DocumentElement, "operator");

            string strAccessClass   = ""; // 索书号中的分类号
            string strBiblioRecPath = ""; // 书目记录路径

            string strLocation = "";      // 册馆藏地点

            XmlNode nodeItem   = null;
            string  strItemXml = DomUtil.GetElementText(dom.DocumentElement,
                                                        "itemRecord", out nodeItem);
            string strItemRecPath = "";
            if (nodeItem != null)
            {
                strItemRecPath = DomUtil.GetAttr(nodeItem, "recPath");
            }

            // 册记录相关的书目记录路径,这个后面统一提取,就不用日志记录中的数据了

            XmlNode nodeReader   = null;
            string  strReaderXml = DomUtil.GetElementText(dom.DocumentElement,
                                                          "readerRecord", out nodeReader);
            string strReaderRecPath = DomUtil.GetAttr(nodeReader, "recPath");
            string strReaderDbName  = Global.GetDbName(strReaderRecPath);



            return(0);
        }