Beispiel #1
0
        int DoSearch(
            string strUserName,
            string strIP,
            string strStyle,
            bool bRefresh,
            out string strError)
        {
            strError = "";
            //int nRet = 0;

            bool bIpCount = (strStyle == "ip-count");

            string strQuery = "";

            Hashtable table = new Hashtable();

            table["ip"]       = strIP;
            table["username"] = strUserName;

            strQuery = StringUtil.BuildParameterString(table);

            // 确保延迟刷新被兑现
            this._history.EnsureAdd(this.listView_channel, this._queryState.Clone());    // 如果有必要则加入

            this.listView_channel.Items.Clear();

            EnableControls(false);

            LibraryChannel channel = this.GetChannel();

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在获得服务器通道信息 ...");
            stop.BeginLoop();

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

            this.listView_channel.BeginUpdate();
            try
            {
                int nStart = 0;
                for (; ;)
                {
                    ChannelInfo[] contents = null;

                    long lRet = channel.GetChannelInfo(
                        this.stop,
                        strQuery,
                        strStyle,
                        nStart,
                        -1,
                        out contents,
                        out strError);

                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }
                    if (lRet == 0)
                    {
                        strError = "不存在用户信息。";
                        goto ERROR1;   // not found
                    }

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

                    foreach (ChannelInfo info in contents)
                    {
                        ListViewItem item = new ListViewItem();
                        ListViewUtil.ChangeItemText(item, COLUMN_IP, AlignIpString(info.ClientIP));
                        ListViewUtil.ChangeItemText(item, COLUMN_VIA, info.Via);
                        ListViewUtil.ChangeItemText(item, COLUMN_USERNAME, info.UserName);
                        ListViewUtil.ChangeItemText(item, COLUMN_LIBRARYCODE, info.LibraryCode);

                        if (bIpCount == true)
                        {
                            ListViewUtil.ChangeItemText(item, COLUMN_COUNT, info.Count.ToString());
                        }

                        if (bIpCount == false)
                        {
                            ListViewUtil.ChangeItemText(item, COLUMN_CALLCOUNT, info.CallCount.ToString());
                        }

                        ListViewUtil.ChangeItemText(item, COLUMN_SESSIONID, info.SessionID);
                        ListViewUtil.ChangeItemText(item, COLUMN_LOCATION, info.Location);
                        ListViewUtil.ChangeItemText(item, COLUMN_LANG, info.Lang);

                        item.SubItems[0].Font = new Font("Courier New", this.Font.Size);

                        this.listView_channel.Items.Add(item);
                    }

                    nStart += contents.Length;
                    if (nStart >= lRet)
                    {
                        break;
                    }
                }

                this.label_channel_message.Text = this.listView_channel.Items.Count.ToString();

                this._queryState.Query   = strQuery;
                this._queryState.Style   = strStyle;
                this._queryState.Message = this.label_channel_message.Text;

                // 保存当前状态
                if (bRefresh == true)
                {
                    this._history.Refresh(this.listView_channel, this._queryState.Clone(), true);    // 滞后刷新
                }
                else
                {
                    this._history.Add(this.listView_channel, this._queryState.Clone(), true);    // 滞后加入
                }
#if NO
                if (bIpCount == true)
                {
                    this._bCountMode = true;
                }
                else
                {
                    this._bCountMode = false;
                }
#endif
            }
            finally
            {
                this.listView_channel.EndUpdate();

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

                this.ReturnChannel(channel);

                EnableControls(true);
            }

            RefreshBackForwardButtons();
            return(0);

ERROR1:
            return(-1);
        }