Пример #1
0
        // 清除所有留存的排序信息,刷新list的标题栏上的陈旧的排序标志
        public static void ClearSortColumns(ListView list)
        {
            ListViewProperty prop = GetListViewProperty(list);

            if (prop == null)
            {
                return;
            }

            prop.SortColumns.Clear();
            SortColumns.ClearColumnSortDisplay(list.Columns);

            prop.CurrentDbName = "";    // 清除记忆
        }
Пример #2
0
        // 检索
        // return:
        //      -1  error
        //      0   succeed
        /// <summary>
        /// 启动查重
        /// </summary>
        /// <param name="strProjectName">查重方案名</param>
        /// <param name="strRecPath">发起记录路径</param>
        /// <param name="strXml">发起记录的 XML</param>
        /// <param name="strUsedProjectName">返回实际使用的方案名</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错; >=0: 命中的记录数</returns>
        public int DoSearch(string strProjectName,
                            string strRecPath,
                            string strXml,
                            out string strUsedProjectName,
                            out string strError)
        {
            strError           = "";
            strUsedProjectName = "";

            if (strProjectName == "<默认>" ||
                strProjectName == "<default>")
            {
                strProjectName = "";
            }

            EventFinish.Reset();

            EnableControls(false);

            LibraryChannel channel     = this.GetChannel();
            TimeSpan       old_timeout = channel.Timeout;

            channel.Timeout = TimeSpan.FromMinutes(2);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在进行查重 ...");
            stop.BeginLoop();

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

            try
            {
                this.ClearDupState();

                this.listView_browse.Items.Clear();
                // 2008/11/22
                this.SortColumns.Clear();
                SortColumns.ClearColumnSortDisplay(this.listView_browse.Columns);

                string strBrowseStyle = "cols";
                if (this.checkBox_includeLowCols.Checked == false)
                {
                    strBrowseStyle += ",excludecolsoflowthreshold";
                }

                long lRet = channel.SearchDup(
                    stop,
                    strRecPath,
                    strXml,
                    strProjectName,
                    "includeoriginrecord", // includeoriginrecord
                    out strUsedProjectName,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                long lHitCount = lRet;

                if (lHitCount == 0)
                {
                    goto END1;   // 查重发现没有命中
                }
                if (stop != null)
                {
                    stop.SetProgressRange(0, lHitCount);
                }

                long lStart    = 0;
                long lPerCount = Math.Min(50, lHitCount);
                // 装入浏览格式
                for (; ;)
                {
                    Application.DoEvents();     // 出让界面控制权

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

                    stop.SetMessage("正在装入浏览信息 " + (lStart + 1).ToString() + " - " + (lStart + lPerCount).ToString() + " (命中 " + lHitCount.ToString() + " 条记录) ...");

                    DupSearchResult[] searchresults = null;

                    lRet = channel.GetDupSearchResult(
                        stop,
                        lStart,
                        lPerCount,
                        strBrowseStyle, // "cols,excludecolsoflowthreshold",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }

                    if (lRet == 0)
                    {
                        break;
                    }

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

                    // 处理浏览结果
                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        DupSearchResult result = searchresults[i];

                        ListViewUtil.EnsureColumns(this.listView_browse,
                                                   2 + (result.Cols == null ? 0 : result.Cols.Length),
                                                   200);

                        if (this.checkBox_returnAllRecords.Checked == false)
                        {
                            // 遇到第一个权值较低的,就中断全部获取浏览过程
                            if (result.Weight < result.Threshold)
                            {
                                goto END1;
                            }
                        }

                        ListViewItem item = new ListViewItem();
                        item.Text = result.Path;
                        item.SubItems.Add(result.Weight.ToString());
                        if (result.Cols != null)
                        {
                            for (int j = 0; j < result.Cols.Length; j++)
                            {
                                item.SubItems.Add(result.Cols[j]);
                            }
                        }
                        this.listView_browse.Items.Add(item);

                        if (item.Text == this.RecordPath)
                        {
                            // 如果就是发起记录自己  2008/2/29
                            item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                            item.BackColor  = Color.LightGoldenrodYellow;
                            item.ForeColor  = SystemColors.GrayText; // 表示就是发起记录自己
                        }
                        else if (result.Weight >= result.Threshold)
                        {
                            item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                            item.BackColor  = Color.LightGoldenrodYellow;
                        }
                        else
                        {
                            item.ImageIndex = ITEMTYPE_NORMAL;
                        }

                        if (stop != null)
                        {
                            stop.SetProgressValue(lStart + i + 1);
                        }
                    }

                    lStart += searchresults.Length;
                    if (lStart >= lHitCount || lPerCount <= 0)
                    {
                        break;
                    }
                }

END1:
                this.SetDupState();

                return((int)lHitCount);
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();

                EventFinish.Set();

                channel.Timeout = old_timeout;
                this.ReturnChannel(channel);

                EnableControls(true);
            }


ERROR1:
            return(-1);
        }
Пример #3
0
        // 检索
        // return:
        //      -1  error
        //      0   succeed
        public int DoSearch(string strProjectName,
                            string strRecPath,
                            string strXml,
                            out string strUsedProjectName,
                            out string strError)
        {
            strError           = "";
            strUsedProjectName = "";

            if (strProjectName == "<默认>" ||
                strProjectName == "<default>")
            {
                strProjectName = "";
            }

            EventFinish.Reset();

            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在进行查重 ...");
            stop.BeginLoop();

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

            try
            {
                this.ClearDupState(true);
                this.listView_browse.Items.Clear();

                // 获得server url
                if (String.IsNullOrEmpty(this.LibraryServerName) == true)
                {
                    strError = "尚未指定服务器名";
                    goto ERROR1;
                }
                dp2Server server = this.MainForm.Servers.GetServerByName(this.LibraryServerName);
                if (server == null)
                {
                    strError = "服务器名为 '" + this.LibraryServerName + "' 的服务器不存在...";
                    goto ERROR1;
                }

                this.SortColumns.Clear();
                SortColumns.ClearColumnSortDisplay(this.listView_browse.Columns);

                string strBrowseStyle = "cols";
                if (this.checkBox_includeLowCols.Checked == false)
                {
                    strBrowseStyle += ",excludecolsoflowthreshold";
                }

                string strServerUrl = server.Url;

                this.Channel = this.Channels.GetChannel(strServerUrl);

                long lRet = Channel.SearchDup(
                    stop,
                    strRecPath,
                    strXml,
                    strProjectName,
                    "includeoriginrecord", // includeoriginrecord
                    out strUsedProjectName,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                long lHitCount = lRet;

                if (lHitCount == 0)
                {
                    goto END1;   // 查重发现没有命中
                }
                long lStart    = 0;
                long lPerCount = Math.Min(50, lHitCount);
                // 装入浏览格式
                for (; ;)
                {
                    Application.DoEvents();     // 出让界面控制权

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

                    stop.SetMessage("正在装入浏览信息 " + (lStart + 1).ToString() + " - " + (lStart + lPerCount).ToString() + " (命中 " + lHitCount.ToString() + " 条记录) ...");

                    lRet = Channel.GetDupSearchResult(
                        stop,
                        lStart,
                        lPerCount,
                        strBrowseStyle, // "cols,excludecolsoflowthreshold",
                        out DupSearchResult[] searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }

                    if (lRet == 0)
                    {
                        break;
                    }

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

                    // 处理浏览结果
                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        DupSearchResult result = searchresults[i];

                        ListViewUtil.EnsureColumns(this.listView_browse,
                                                   2 + (result.Cols == null ? 0 : result.Cols.Length),
                                                   200);

                        if (this.checkBox_returnAllRecords.Checked == false)
                        {
                            // 遇到第一个权值较低的,就中断全部获取浏览过程
                            if (result.Weight < result.Threshold)
                            {
                                goto END1;
                            }
                        }

                        /*
                         * if (result.Cols == null)
                         * {
                         *  strError = "返回的结果行错误 result.Cols == null";
                         *  goto ERROR1;
                         * }
                         *
                         * ListViewUtil.EnsureColumns(this.listView_browse,
                         *  2 + result.Cols.Length,
                         *  200);
                         * */

                        ListViewItem item = new ListViewItem();
                        item.Text = result.Path;
                        item.Tag  = result;
                        item.SubItems.Add(result.Weight.ToString());
                        if (result.Cols != null)
                        {
                            for (int j = 0; j < result.Cols.Length; j++)
                            {
                                item.SubItems.Add(result.Cols[j]);
                            }
                        }
                        this.listView_browse.Items.Add(item);

                        if (item.Text == this.RecordPath)
                        {
                            // 如果就是发起记录自己  2008/2/29
                            item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                            item.BackColor  = Color.LightGoldenrodYellow;
                            item.ForeColor  = SystemColors.GrayText; // 表示就是发起记录自己
                        }
                        else if (result.Weight >= result.Threshold)
                        {
                            item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                            item.BackColor  = Color.LightYellow;
                            item.Font       = new Font(item.Font, FontStyle.Bold);
                        }
                        else
                        {
                            item.ImageIndex = ITEMTYPE_NORMAL;
                        }
                    }

                    lStart += searchresults.Length;
                    if (lStart >= lHitCount || lPerCount <= 0)
                    {
                        break;
                    }
                }

END1:
                this.SetDupState();

                return((int)lHitCount);
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                EventFinish.Set();

                EnableControls(true);
            }


ERROR1:
            return(-1);
        }