コード例 #1
0
        public void EnsureVisible(RegisterLine item)
        {
            int[] row_heights = this.tableLayoutPanel1.GetRowHeights();
            int nYOffs = 0; // row_heights[0];
            int i = 0;  // 1
            foreach (RegisterLine cur_item in this.Items)
            {
                if (cur_item == item)
                    break;
                nYOffs += row_heights[i++];
            }

            // this.AutoScrollPosition = new Point(this.AutoScrollOffset.X, 1000);
            if (nYOffs < -this.AutoScrollPosition.Y)
            {
                this.AutoScrollPosition = new Point(this.AutoScrollOffset.X, nYOffs);
            }
            else if (nYOffs + row_heights[i] > -(this.AutoScrollPosition.Y - this.ClientSize.Height))
            {
                // 刚好进入下部
                this.AutoScrollPosition = new Point(this.AutoScrollOffset.X, nYOffs - this.ClientSize.Height + row_heights[i]);
            }
        }
コード例 #2
0
        public void EnsureVisible(RegisterLine base_line, Rectangle rect)
        {
            // http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.autoscrollposition(v=vs.110).aspx
            // The X and Y coordinate values retrieved are negative if the control has scrolled away from its starting position (0,0). When you set this property, you must always assign positive X and Y values to set the scroll position relative to the starting position.
            ScrollableControl parent = this.tableLayoutPanel1;

            if (base_line != null)
                rect.Y += GetRect(base_line).Y;

            // this.AutoScrollPosition = new Point(this.AutoScrollOffset.X, 1000);
            if (rect.Y < -parent.AutoScrollPosition.Y)
            {
                // parent.AutoScrollPosition = new Point(-parent.AutoScrollPosition.X, rect.Y);
                SetControlOffs(parent, -parent.AutoScrollPosition.X, rect.Y);
            }
            else if (rect.Y + rect.Height > -(parent.AutoScrollPosition.Y - this.ClientSize.Height))
            {
                // 刚好进入下部
                // parent.AutoScrollPosition = new Point(-parent.AutoScrollPosition.X, (rect.Y + rect.Height - this.ClientSize.Height));
                SetControlOffs(parent, -parent.AutoScrollPosition.X, rect.Y + rect.Height - this.ClientSize.Height);
            }
        }
コード例 #3
0
 // parameters:
 //      strPart 事项的那个部分需要可见? all / biblio / items
 public void EnsureVisible(RegisterLine item,
     string strPart = "all")
 {
     if (strPart == "all")
     {
         Rectangle rect = this.GetRect(item);
         EnsureVisible(null, rect);
         return;
     }
     if (strPart == "biblio")
     {
         EnsureVisible(item, item._biblioRegister.GetRect("biblio"));
         return;
     }
     if (strPart == "items")
     {
         EnsureVisible(item, item._biblioRegister.GetRect("items"));
         return;
     }
 }
コード例 #4
0
        // 将一条书目记录下属的若干册记录装入列表
        // return:
        //      -2  用户中断
        //      -1  出错
        //      >=0 装入的册记录条数
        int LoadBiblioSubItems(
            RegisterLine line,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            line._biblioRegister.ClearEntityEditControls("normal");

            string strBiblioRecPath = line._biblioRegister.BiblioRecPath;
            if (string.IsNullOrEmpty(strBiblioRecPath) == true)
            {
                // 册信息部分显示为空
                line._biblioRegister.TrySetBlank("none");
                return 0;
            }

            AccountInfo _currentAccount = _base.GetAccountInfo(line._biblioRegister.ServerName);
            if (_currentAccount == null)
            {
                strError = "服务器名 '" + line._biblioRegister.ServerName + "' 没有配置";
                return -1;
            }

            // 如果不是本地服务器,则不需要装入册记录
            if (_currentAccount.IsLocalServer == false)
            {
                _base.CurrentAccount = null;
                // 册信息部分显示为空
                line._biblioRegister.TrySetBlank("none");
                return 0;
            }

            _channel = _base.GetChannel(_currentAccount.ServerUrl, _currentAccount.UserName);

            this.Progress.OnStop += new StopEventHandler(this.DoStop);
            //this.Progress.Initial("正在装入书目记录 '" + strBiblioRecPath + "' 下属的册记录 ...");
            this.Progress.BeginLoop();
            try
            {
                int nCount = 0;

                long lPerCount = 100; // 每批获得多少个
                long lStart = 0;
                long lResultCount = 0;
                long lCount = -1;
                for (; ; )
                {
                    if (Progress.State != 0)
                    {
                        strError = "用户中断";
                        return -2;
                    }

                    EntityInfo[] entities = null;

                    long lRet = _channel.GetEntities(
             Progress,
             strBiblioRecPath,
             lStart,
             lCount,
             "",  // bDisplayOtherLibraryItem == true ? "getotherlibraryitem" : "",
             "zh",
             out entities,
             out strError);
                    if (lRet == -1)
                        return -1;

                    lResultCount = lRet;

                    if (lRet == 0)
                    {
                        // 册信息部分显示为空
                        line._biblioRegister.TrySetBlank("none");
                        return nCount;
                    }

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

                    foreach (EntityInfo entity in entities)
                    {
                        // string strXml = entity.OldRecord;
                        if (entity.ErrorCode != ErrorCodeValue.NoError)
                        {
                            // TODO: 显示错误信息
                            continue;
                        }

                        // 添加一个新的册对象
                        nRet = line._biblioRegister.NewEntity(entity.OldRecPath,
                            entity.OldTimestamp,
                            entity.OldRecord,
                            false,  // 不必滚入视野
                            out strError);
                        if (nRet == -1)
                            return -1;

                        nCount++;
                    }

                    lStart += entities.Length;
                    if (lStart >= lResultCount)
                        break;

                    if (lCount == -1)
                        lCount = lPerCount;

                    if (lStart + lCount > lResultCount)
                        lCount = lResultCount - lStart;
                }

                return nCount;
            }
            finally
            {
                this.Progress.EndLoop();
                this.Progress.OnStop -= new StopEventHandler(this.DoStop);
                // this.Progress.Initial("");

                _base.ReturnChannel(_channel);
                _channel = null;
                _currentAccount = null;
            }
        }
コード例 #5
0
        Rectangle GetRect(RegisterLine item)
        {
            int[] row_heights = this.tableLayoutPanel1.GetRowHeights();
            int nYOffs = 0;
            int i = 0;
            foreach (RegisterLine cur_item in this.Items)
            {
                if (cur_item == item)
                    break;
                nYOffs += row_heights[i++];
            }

            int nHeight = 0;
            if (i < row_heights.Length)
                nHeight = row_heights[i];

            Rectangle rect = new Rectangle(0, nYOffs, this.tableLayoutPanel1.Width, nHeight); 

            return rect;
        }
コード例 #6
0
ファイル: TestForm.cs プロジェクト: paopaofeng/dp2
 private void button_entitiesControl_addLine_Click(object sender, EventArgs e)
 {
     RegisterLine line = new RegisterLine(this.entitiesControl1);
     this.entitiesControl1.InsertNewLine(0, line, true);
 }
コード例 #7
0
        // load_items / save / search_biblio
        internal void AddTask(RegisterLine line,
            string strTaskName,
            object tag = null)
        {
            LineTask task = new LineTask();
            task.TaskName = strTaskName;
            task.Line = line;
            task.Tag = tag;
            lock (this._loadEntityTasks)
            {
                this._loadEntityTasks.Add(task);
            }

            this.ActivateThread();
        }
コード例 #8
0
        // 新添加一个书目事项
        public void AddNewBiblio(string strText)
        {
            RegisterLine line = new RegisterLine(this);
            line.BiblioBarcode = strText;

            this.InsertNewLine(0, line, true);
            line.label_color.Focus();

            line._biblioRegister.BarColor = "B";    // 黑色,表示刚加入,还来不及处理
            this.SetColorList();

            this.AddTask(line, "search_biblio");

            // 选定刚新增的事项
            this.SelectItem(line, true);
            line._biblioRegister.Focus();
            // 确保事项可见
            this.EnsureVisible(line);
        }
コード例 #9
0
        // 针对 dp2library 服务器进行检索
        // parameters:
        //  
        // return:
        //      -1  出错
        //      >=0 命中的记录数
        int SearchLineDp2library(RegisterLine line,
            AccountInfo account,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            // ??? _currentAccount = account;

            _channel = _base.GetChannel(account.ServerUrl, account.UserName);
            _channel.Timeout = new TimeSpan(0, 0, 5);   // 超时值为 5 秒
            try
            {
                string strQueryWord = line.BiblioBarcode;

                string strFromStyle = "";

                try
                {
                    strFromStyle = this.MainForm.GetBiblioFromStyle("ISBN");
                }
                catch (Exception ex)
                {
                    strError = ex.Message;
                    goto ERROR1;
                }

                if (String.IsNullOrEmpty(strFromStyle) == true)
                {
                    strError = "GetFromStyle()没有找到 '" + "ISBN" + "' 对应的style字符串";
                    goto ERROR1;
                }

                string strMatchStyle = "left";  // BiblioSearchForm.GetCurrentMatchStyle(this.comboBox_matchStyle.Text);
                if (string.IsNullOrEmpty(strQueryWord) == true)
                {
                    if (strMatchStyle == "null")
                    {
                        strQueryWord = "";

                        // 专门检索空值
                        strMatchStyle = "exact";
                    }
                    else
                    {
                        // 为了在检索词为空的时候,检索出全部的记录
                        strMatchStyle = "left";
                    }
                }
                else
                {
                    if (strMatchStyle == "null")
                    {
                        strError = "检索空值的时候,请保持检索词为空";
                        goto ERROR1;
                    }
                }

                ServerInfo server_info = null;

                if (line != null)
                    line.BiblioSummary = "正在获取服务器 " + account.ServerName + " 的配置信息 ...";

                // 准备服务器信息
                nRet = _base.GetServerInfo(
                    // line,
                    _channel,
                    account,
                    out server_info,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;    // 可以不报错 ?

                line.BiblioSummary = "正在针对 "+account.ServerName+ " \r\n检索 " + line.BiblioBarcode + " ...";

                string strQueryXml = "";
                long lRet = _channel.SearchBiblio(Progress,
                    server_info == null ? "<全部>" : server_info.GetBiblioDbNames(),    // "<全部>",
                    strQueryWord,   // this.textBox_queryWord.Text,
                    1000,
                    strFromStyle,
                    strMatchStyle,
                    _base.Lang,
                    null,   // strResultSetName
                    "",    // strSearchStyle
                    "", // strOutputStyle
                    out strQueryXml,
                    out strError);
                if (lRet == -1)
                {
                    strError = "针对服务器 '"+account.ServerName+"' 检索出错: " + strError;
                    goto ERROR1;
                }

                // 装入浏览格式
                long lHitCount = lRet;

                long lStart = 0;
                long lCount = lHitCount;
                DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                string strStyle = "id";

                List<string> biblio_recpaths = new List<string>();
                // 装入浏览格式
                for (; ; )
                {
                    if (this.Progress != null && this.Progress.State != 0)
                    {
                        break;
                    }
                    // DoTasks();

                    lRet = _channel.GetSearchResult(
                        this.Progress,
                        null,   // strResultSetName
                        lStart,
                        lCount,
                        strStyle, // bOutputKeyCount == true ? "keycount" : "id,cols",
                        _base.Lang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条," + strError;
                        goto ERROR1;
                    }

                    if (lRet == 0)
                        break;

                    // 处理浏览结果

                    foreach (DigitalPlatform.CirculationClient.localhost.Record searchresult in searchresults)
                    {
                        biblio_recpaths.Add(searchresult.Path);
                    }

                    {
                        // 获得书目摘要
                        BiblioLoader loader = new BiblioLoader();
                        loader.Channel = _channel;
                        loader.Stop = this.Progress;
                        loader.Format = "xml";
                        loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp;
                        loader.RecPaths = biblio_recpaths;

                        try
                        {
                            int i = 0;
                            foreach (BiblioItem item in loader)
                            {
                                string strXml = item.Content;

                                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;
                                }

                                string strBrowseText = "";
                                nRet = BuildMarcBrowseText(
                                    strMarcSyntax,
                                    strMARC,
                                    out strBrowseText,
                                    out strError);
                                if (nRet == -1)
                                {
                                    strError = "MARC记录转换到浏览格式时出错: " + strError;
                                    goto ERROR1;
                                }

                                RegisterBiblioInfo info = new RegisterBiblioInfo();
                                info.OldXml = strMARC;
                                info.Timestamp = item.Timestamp;
                                info.RecPath = item.RecPath + "@" + account.ServerName;
                                info.MarcSyntax = strMarcSyntax;
                                line.AddBiblioBrowseLine(
                                    -1,
                                    info.RecPath,
                                    strBrowseText,
                                    info);
                                i++;
                            }
                        }
                        catch (Exception ex)
                        {
                            strError = ex.Message;
                            goto ERROR1;
                        }


                        // lIndex += biblio_recpaths.Count;
                        biblio_recpaths.Clear();
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }


                return (int)lHitCount;

            }
            finally
            {
                _base.ReturnChannel(_channel);
                _channel = null;
            }

        ERROR1:
#if NO
            line.SetDisplayMode("summary");
            line.SetBiblioSearchState("error");
            line.BiblioSummary = strError;
#endif
            line.AddBiblioBrowseLine(strError, BiblioRegisterControl.TYPE_ERROR);

            return -1;
        }
コード例 #10
0
        void SearchLine(RegisterLine line)
        {
            string strError = "";
            int nRet = 0;

            if (this.ServersDom == null)
            {
                strError = "ServersDom 为空";
                goto ERROR1;
            }

            string strTotalError = "";

            this.Progress.OnStop += new StopEventHandler(this.DoStop);
            // this.Progress.Initial("进行一轮任务处理...");
            this.Progress.BeginLoop();
            try
            {
                int nHitCount = 0;

                line.SetBiblioSearchState("searching");
                line.BiblioSummary = "正在检索 " + line.BiblioBarcode + " ...";

                XmlNodeList servers = this.ServersDom.DocumentElement.SelectNodes("server");
                foreach (XmlElement server in servers)
                {
                    AccountInfo account = EntityRegisterBase.GetAccountInfo(server);
                    Debug.Assert(account != null, "");
                    _base.CurrentAccount = account;
#if NO
                string strName = server.GetAttribute("name");
                string strType = server.GetAttribute("type");
                string strUrl = server.GetAttribute("url");
                string strUserName = server.GetAttribute("userName");
                string strPassword = server.GetAttribute("password");
                // e.Password = this.MainForm.DecryptPasssword(e.Password);
                string strIsReader = server.GetAttribute("isReader");
#endif

                    if (account.ServerType == "dp2library")
                    {
                        nRet = SearchLineDp2library(line,
                            account,
                            out strError);
                        if (nRet == -1)
                            strTotalError += strError + "\r\n";
                        else
                            nHitCount += nRet;
                    }
                    else if (account.ServerType == "amazon")
                    {
                        nRet = SearchLineAmazon(line,
                            account,
                            out strError);
                        if (nRet == -1)
                            strTotalError += strError + "\r\n";
                        else
                            nHitCount += nRet;
                    }
                }

                line.SetBiblioSearchState(nHitCount.ToString());

                // 
                if (nHitCount == 1)
                {
                    // TODO: 如果有报错的行,是否就不要自动模拟双击了? 假如这种情况是因为红泥巴服务器持续无法访问引起的,需要有配置办法可以临时禁用这个数据源

                    // 模拟双击
                    int index = line._biblioRegister.GetFirstRecordIndex();
                    if (index == -1)
                    {
                        strError = "获得第一个浏览记录 index 时出错";
                        goto ERROR1;
                    }
                    nRet = line._biblioRegister.SelectBiblio(index,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                }
                else
                {
                    if (nHitCount > 1)
                        line.SetDisplayMode("select");
                    else
                    {
                        // 进入详细状态,可以新创建一条记录
                        line.AddBiblioBrowseLine(BiblioRegisterControl.TYPE_INFO,
                            "没有命中书目记录。双击本行新创建书目记录",
                            "",
                            BuildBlankBiblioInfo(line.BiblioBarcode)); 
                        line.SetDisplayMode("select");
                    }
                }
            }
            finally
            {
                this.Progress.EndLoop();
                this.Progress.OnStop -= new StopEventHandler(this.DoStop);
                // this.Progress.Initial("");
            }

            if (string.IsNullOrEmpty(strTotalError) == false)
            {
                // DisplayFloatErrorText(strTotalError);

                line._biblioRegister.BarColor = "R";   // 红色,需引起注意
                this.SetColorList();
            }
            else
            {
                line._biblioRegister.BarColor = "Y";   // 黄色表示等待选择?
                this.SetColorList();
            }
            return;
        ERROR1:
            line.SetDisplayMode("summary");
            line.SetBiblioSearchState("error");
            line.BiblioSummary = strError;
            DisplayFloatErrorText(strError);

            line._biblioRegister.BarColor = "R";   // 红色,需引起注意
            this.SetColorList();
        }
コード例 #11
0
        // return:
        //      -1  出错
        //      >=0 命中的记录数
        int SearchLineAmazon(RegisterLine line,
            AccountInfo account,
            out string strError)
        {
            strError = "";

            // ??? this._currentAccount = account;

            line.BiblioSummary = "正在针对 " + account.ServerName + " \r\n检索 " + line.BiblioBarcode + " ...";

            AmazonSearch search = new AmazonSearch();
            // search.MainForm = this.MainForm;
            search.TempFileDir = this.MainForm.UserTempDir;

            // 多行检索中的一行检索
            int nRedoCount = 0;
        REDO:
            int nRet = search.Search(
                account.ServerUrl,
                line.BiblioBarcode.Replace("-", ""),
                "ISBN",
                "[default]",
                true,
                out strError);
            if (nRet == -1)
            {
                if (search.Exception != null && search.Exception is WebException)
                {
                    WebException e = search.Exception as WebException;
                    if (e.Status == WebExceptionStatus.ProtocolError)
                    {
                        // 重做
                        if (nRedoCount < 2)
                        {
                            nRedoCount++;
                            Thread.Sleep(1000);
                            goto REDO;
                        }

#if NO
                        // 询问是否重做
                        DialogResult result = MessageBox.Show(this,
"检索 '" + strLine + "' 时发生错误:\r\n\r\n" + strError + "\r\n\r\n是否重试?\r\n\r\n(Yes: 重试; No: 跳过这一行继续检索后面的行; Cancel: 中断整个检索操作",
"AmazonSearchForm",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
                        if (result == System.Windows.Forms.DialogResult.Retry)
                        {
                            Thread.Sleep(1000);
                            goto REDO;
                        }
                        if (result == System.Windows.Forms.DialogResult.Cancel)
                            return -1;
                        goto CONTINUE;
#endif
                        goto ERROR1;
                    }
                }
                goto ERROR1;
            }


            nRet = search.LoadBrowseLines(appendBrowseLine,
                line,
                false,
                out strError);
            if (nRet == -1)
                goto ERROR1;
            return nRet;

            ERROR1:
            strError = "针对服务器 '" + account.ServerName + "' 检索出错: " + strError;
            line.AddBiblioBrowseLine(strError, BiblioRegisterControl.TYPE_ERROR);
            return -1;
        }
コード例 #12
0
        // 获得书目记录的XML格式
        // parameters:
        int GetBiblioXml(
            RegisterLine line,
            out string strXml,
            out string strError)
        {
            strError = "";
            strXml = "";

            string strBiblioDbName = Global.GetDbName(line._biblioRegister.BiblioRecPath);

            string strMarcSyntax = "";

            // TODO: 如何获得远程其他 dp2library 服务器的书目库的 syntax?
            // 获得库名,根据库名得到marc syntax
            if (String.IsNullOrEmpty(strBiblioDbName) == false)
                strMarcSyntax = MainForm.GetBiblioSyntax(strBiblioDbName);

            // 在当前没有定义MARC语法的情况下,默认unimarc
            if (String.IsNullOrEmpty(strMarcSyntax) == true)
                strMarcSyntax = "unimarc";

            // 2008/5/16 changed
            string strMARC = line._biblioRegister.GetMarc();
            XmlDocument domMarc = null;
            int nRet = MarcUtil.Marc2Xml(strMARC,
                strMarcSyntax,
                out domMarc,
                out strError);
            if (nRet == -1)
                return -1;

            // 因为domMarc是根据MARC记录合成的,所以里面没有残留的<dprms:file>元素,也就没有(创建新的id前)清除的需要

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

#if NO
            // 合成其它XML片断
            if (domXmlFragment != null
                && string.IsNullOrEmpty(domXmlFragment.DocumentElement.InnerXml) == false)
            {
                XmlDocumentFragment fragment = domMarc.CreateDocumentFragment();
                try
                {
                    fragment.InnerXml = domXmlFragment.DocumentElement.InnerXml;
                }
                catch (Exception ex)
                {
                    strError = "fragment XML装入XmlDocumentFragment时出错: " + ex.Message;
                    return -1;
                }

                domMarc.DocumentElement.AppendChild(fragment);
            }
#endif

            strXml = domMarc.OuterXml;
            return 0;
        }
コード例 #13
0
        // 分批进行保存
        // return:
        //      -2  部分成功,部分失败
        //      -1  出错
        //      0   保存成功,没有错误和警告
        int SaveEntities(
            RegisterLine line,
            EntityInfo[] entities,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            bool bWarning = false;
            EntityInfo[] errorinfos = null;
            string strWarning = "";

            // 确定目标服务器 目标书目库
            AccountInfo _currentAccount = _base.GetAccountInfo(line._biblioRegister.ServerName);
            if (_currentAccount == null)
            {
                strError = "' 服务器名 '" + line._biblioRegister.ServerName + "' 没有配置";
                return -1;
            }

            _channel = _base.GetChannel(_currentAccount.ServerUrl, _currentAccount.UserName);
            try
            {

                string strBiblioRecPath = line._biblioRegister.BiblioRecPath;

                int nBatch = 100;
                for (int i = 0; i < (entities.Length / nBatch) + ((entities.Length % nBatch) != 0 ? 1 : 0); i++)
                {
                    int nCurrentCount = Math.Min(nBatch, entities.Length - i * nBatch);
                    EntityInfo[] current = GetPart(entities, i * nBatch, nCurrentCount);

                    long lRet = _channel.SetEntities(
         Progress,
         strBiblioRecPath,
         entities,
         out errorinfos,
         out strError);
                    if (lRet == -1)
                        return -1;

                    // 把出错的事项和需要更新状态的事项兑现到显示、内存
                    string strError1 = "";
                    if (line._biblioRegister.RefreshOperResult(errorinfos, out strError1) == true)
                    {
                        bWarning = true;
                        strWarning += " " + strError1;
                    }

                    if (lRet == -1)
                        return -1;
                }

                if (string.IsNullOrEmpty(strWarning) == false)
                    strError += " " + strWarning;

                if (bWarning == true)
                    return -2;

                // line._biblioRegister.EntitiesChanged = false;    // 所有册都保存成功了
                return 0;
            }
            finally
            {
                _base.ReturnChannel(_channel);
                _channel = null;
                _currentAccount = null;
            }
        }
コード例 #14
0
        // 保存书目记录和下属的册记录
        void SaveLine(RegisterLine line)
        {
            string strError = "";
            int nRet = 0;

            this.Progress.OnStop += new StopEventHandler(this.DoStop);
            // this.Progress.Initial("进行一轮任务处理...");
            this.Progress.BeginLoop();
            try
            {
                string strCancelSaveBiblio = "";

                AccountInfo _currentAccount = _base.GetAccountInfo(line._biblioRegister.ServerName);
            if (_currentAccount == null)
            {
                strError = "服务器名 '" + line._biblioRegister.ServerName + "' 没有配置";
                goto ERROR1;
            }

                // line.SetBiblioSearchState("searching");
                if (line._biblioRegister.BiblioChanged == true
                    || Global.IsAppendRecPath(line._biblioRegister.BiblioRecPath) == true
                    || _currentAccount.IsLocalServer == false)
                {
                    // TODO: 确定目标 dp2library 服务器 目标书目库
                    string strServerName = "";
                    string strBiblioRecPath = "";
                    // 根据书目记录的路径,匹配适当的目标
                    // return:
                    //      -1  出错
                    //      0   没有找到
                    //      1   找到
                    nRet = GetTargetInfo(line,
                        _currentAccount.IsLocalServer == false? true : false,
                        out strServerName,
                        out strBiblioRecPath);
#if NO
                    if (nRet != 1)
                    {
                        strError = "line (servername='" + line._biblioRegister.ServerName + "' bibliorecpath='" + line._biblioRegister.BiblioRecPath + "') 没有找到匹配的保存目标";
                        goto ERROR1;
                    }
#endif
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 0)
                    {
                        strError = "来自服务器 '" + line._biblioRegister.ServerName + "' 的书目记录 '" + line._biblioRegister.BiblioRecPath + "' 没有找到匹配的保存目标";
                        bool bAppend = Global.IsAppendRecPath(line._biblioRegister.BiblioRecPath);
                        if (bAppend == true || _currentAccount.IsLocalServer == false)
                            goto ERROR1;

                        // 虽然书目记录无法保存,但继续寻求保存册记录
                        strCancelSaveBiblio = strError;
                        goto SAVE_ENTITIES;
                    }

                    // if nRet == 0 并且 书目记录路径不是追加型的
                    // 虽然无法兑现修改后保存,但是否可以依然保存实体记录?

                    string strXml = "";
                    nRet = GetBiblioXml(
                        line,
                        out strXml,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    string strWarning = "";
                    string strOutputPath = "";
                    byte[] baNewTimestamp = null;
                    nRet = SaveXmlBiblioRecordToDatabase(
                        strServerName,
                        strBiblioRecPath,
                        strXml,
                        line._biblioRegister.Timestamp,
                        out strOutputPath,
                out baNewTimestamp,
                out strWarning,
                out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    line._biblioRegister.ServerName = strServerName;
                    line._biblioRegister.BiblioRecPath = strOutputPath;
                    line._biblioRegister.Timestamp = baNewTimestamp;
                    line._biblioRegister.BiblioChanged = false;
                }

                // line.SetDisplayMode("summary");

                SAVE_ENTITIES:
                // 保存下属的册记录
                {
                    EntityInfo[] entities = null;
                    // 构造用于保存的实体信息数组
                    nRet = line._biblioRegister.BuildSaveEntities(
                        "change",
                        null,
                        out entities,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    if (entities.Length > 0)
                    {
                        // 分批进行保存
                        // return:
                        //      -2  部分成功,部分失败
                        //      -1  出错
                        //      0   保存成功,没有错误和警告
                        nRet = SaveEntities(
                            line,
                            entities,
                            out strError);
                        if (nRet == -1 || nRet == -2)
                            goto ERROR1;
                        line._biblioRegister.EntitiesChanged = false;
                    }
                    else
                    {
                        line._biblioRegister.EntitiesChanged = false;
                        line._biblioRegister.BarColor = "G";   // 绿色
                        return;
                    }
                }

                line.SetDisplayMode("summary");

                if (string.IsNullOrEmpty(strCancelSaveBiblio) == false)
                {
                    line.BiblioSummary = "书目记录无法保存,但册记录保存成功\r\n(" + strCancelSaveBiblio + ")";

                    line._biblioRegister.BarColor = "R";   // 表示操作未完全完成
                }
                else
                {
                    line.BiblioSummary = "保存成功";

                    line._biblioRegister.BarColor = "G";   // 绿色
                }
                this.SetColorList();
                return;
            }
            finally
            {
                this.Progress.EndLoop();
                this.Progress.OnStop -= new StopEventHandler(this.DoStop);
                // this.Progress.Initial("");
            }
        ERROR1:
            line.SetDisplayMode("summary");
            line.SetBiblioSearchState("error");
            line.BiblioSummary = strError;

            line._biblioRegister.BarColor = "R";   // 红色
            this.SetColorList();
        }
コード例 #15
0
        // 根据书目记录的路径,匹配适当的目标
        // parameters:
        //      bAllowCopyTo    是否允许书目记录复制到其他库?这发生在原始库不让 overwrite 的时候
        // return:
        //      -1  出错
        //      0   没有找到
        //      1   找到
        int GetTargetInfo(RegisterLine line,
            bool bAllowCopyTo,
            out string strServerName,
            out string strBiblioRecPath)
        {
            strServerName = "";
            strBiblioRecPath = "";

            // string strEditServerUrl = "";
            string strEditServerName = line._biblioRegister.ServerName;
            string strEditBiblioRecPath = line._biblioRegister.BiblioRecPath;

            if (string.IsNullOrEmpty(strEditServerName) == false
                && string.IsNullOrEmpty(strEditBiblioRecPath) == false)
            {
                // 验证 edit 中的书目库名,是否是可以写入的 ?
                XmlElement server = (XmlElement)this.ServersDom.DocumentElement.SelectSingleNode("server[@name='" + strEditServerName + "']");
                if (server != null)
                {
                    if (IsWritable(server, strEditBiblioRecPath) == true)
                    {
                        strServerName = strEditServerName;
                        strBiblioRecPath = strEditBiblioRecPath;
                        return 1;
                    }

                    if (bAllowCopyTo == false)
                        return 0;
                }
            }

            // 此后都是寻找可以追加写入的
            // 获得第一个可以写入的服务器名
            XmlNodeList servers = this.ServersDom.DocumentElement.SelectNodes("server");
            foreach (XmlElement server in servers)
            {
                XmlNodeList databases = server.SelectNodes("database");
                foreach (XmlElement database in databases)
                {
                    string strDatabaseName = database.GetAttribute("name");
                    if (string.IsNullOrEmpty(strDatabaseName) == true)
                        continue;
                    bool bIsTarget = DomUtil.GetBooleanParam(database, "isTarget", false);
                    if (bIsTarget == false)
                        continue;

                    string strAccess = database.GetAttribute("access");
                    if (StringUtil.IsInList("append", strAccess) == false)
                        continue;
                    strServerName = server.GetAttribute("name");
                    strBiblioRecPath = strDatabaseName + "/?";
                    return 1;
                }
            }

            return 0;
        }
コード例 #16
0
 public void AddDeleteItemTask(RegisterLine line, EntityEditControl edit)
 {
     this.AddTask(line, "delete_items", edit);
 }
コード例 #17
0
        void DeleteItem(RegisterLine line, EntityEditControl edit)
        {
            string strError = "";
            int nRet = 0;

            this.Progress.OnStop += new StopEventHandler(this.DoStop);
            this.Progress.BeginLoop();
            try
            {
#if NO
                this._currentAccount = this.GetAccountInfo(line._biblioRegister.ServerName);
                if (this._currentAccount == null)
                {
                    strError = "服务器名 '" + line._biblioRegister.ServerName + "' 没有配置";
                    goto ERROR1;
                }
#endif

                List<EntityEditControl> controls = new List<EntityEditControl>();
                controls.Add(edit);

                // line.SetDisplayMode("summary");

                // 删除下属的册记录
                {
                    EntityInfo[] entities = null;
                    // 构造用于保存的实体信息数组
                    nRet = line._biblioRegister.BuildSaveEntities(
                        "delete",
                        controls,
                        out entities,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    // 分批进行保存
                    // return:
                    //      -2  部分成功,部分失败
                    //      -1  出错
                    //      0   保存成功,没有错误和警告
                    nRet = SaveEntities(
                        line,
                        entities,
                        out strError);
                    if (nRet == -1 || nRet == -2)
                        goto ERROR1;

                    // 兑现视觉删除
                    line._biblioRegister.RemoveEditControl(edit);

                    // line._biblioRegister.EntitiesChanged = false;
                }

                return;
            }
            finally
            {
                this.Progress.EndLoop();
                this.Progress.OnStop -= new StopEventHandler(this.DoStop);
                // this.Progress.Initial("");
            }
        ERROR1:
            // line.SetDisplayMode("summary");
            // line.SetBiblioSearchState("error");
            // line.BiblioSummary = strError;
            BiblioRegisterControl.SetEditErrorInfo(edit, strError);
            line._biblioRegister.BarColor = "R";   // 红色
            this.SetColorList();
        }
コード例 #18
0
ファイル: EntityRegisterForm.cs プロジェクト: paopaofeng/dp2
        void _scanBarcodeForm_BarcodeScaned(object sender, ScanedEventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (string.IsNullOrEmpty(e.Barcode) == true)
            {
                Console.Beep();
                return;
            }

            // 自动切换到 登记 属性页,避免操作者看不到扫入了什么内容
            if (this.tabControl_main.SelectedTab != this.tabPage_register)
                this.tabControl_main.SelectedTab = this.tabPage_register;

            // 清除浮动的错误信息
            this._floatingMessage.Text = "";

            // 把册条码号直接加入行中,然后等待专门的线程来装载刷新
            // 要查重
#if NO
            ListViewItem dup = ListViewUtil.FindItem(this.listView_in, e.Barcode, COLUMN_BARCODE);
            if (dup != null)
            {
                Console.Beep();
                ListViewUtil.SelectLine(dup, true);
                MessageBox.Show(this, "您扫入的册条码号 ‘" + e.Barcode + "’ 在列表中已经存在了,请注意不要重复扫入");
                this._scanBarcodeForm.Activate();
                return;
            }

            ListViewItem item = new ListViewItem();
            ListViewUtil.ChangeItemText(item, COLUMN_BARCODE, e.Barcode);
            this.listView_in.Items.Add(item);
            ListViewUtil.SelectLine(item, true);
            item.EnsureVisible();
#endif
            string strText = e.Barcode;

            // 如果是 ISBN,则新装入一个书目记录
            // TODO: 装入前需要对整个 list 进行查重,如果前面已经有同样 ISBN 的书目,要提醒
            if (QuickChargingForm.IsISBN(ref strText) == true)
            {
#if NO
                RegisterLine line = new RegisterLine(this.entityRegisterControl1);
                line.BiblioBarcode = strText;

                this.entityRegisterControl1.InsertNewLine(0, line, true);
                line.label_color.Focus();

                this.entityRegisterControl1.SetColorList();

                this.entityRegisterControl1.AddTask(line, "search_biblio");

                // 选定刚新增的事项
                this.entityRegisterControl1.SelectItem(line, true);
                // 确保事项可见
                this.entityRegisterControl1.EnsureVisible(line);
#endif
                this.entityRegisterControl1.AddNewBiblio(strText);
            }
            else
            {
                // 当作册条码号进入
                nRet = this.entityRegisterControl1.AddNewEntity(strText,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
            }

            // this.entityRegisterControl1.ActivateThread();
            return;
        ERROR1:
            MessageBox.Show(this, strError);
            this._scanBarcodeForm.Focus();
        }