private List<ContextBean> queryContextList()
        {
            List<ContextBean> ctxList = new List<ContextBean>();

            try
            {
                SetStatus("Querying...Please wait...");
                this.Cursor = Cursors.WaitCursor;

                QueryServiceManager.QueryRequestQuery req = new global::QueryServiceControl.QueryServiceManager.QueryRequestQuery();
                req.query = new QueryServiceManager.query();
                req.query.resource = cbResources.SelectedValue.ToString();

                req.query.Items = new string[] { req.query.resource };

                req.query.ItemsElementName = new global::QueryServiceControl.QueryServiceManager.ItemsChoiceType[] {
                        global::QueryServiceControl.QueryServiceManager.ItemsChoiceType.contextList
                    };

                qsm.Url = cbServiceUrls.Text;

                QueryServiceManager.resultset result = qsm.query(req);
                if (result == null || result.Items == null || result.Items.Length <= 0)
                {
                    SetStatus("No result");
                    this.Cursor = Cursors.Default;
                    return ctxList;
                }

                // add default empty context
                ctxList.Add(new ContextBean("All", "", ""));

                foreach (QueryServiceManager.context ctx in result.Items)
                {
                    ctxList.Add(new ContextBean(ctx));
                }

                ctxList.Sort(new ContextBeanComparer());
            }
            catch (Exception ex)
            {
                MessageBox.Show("queryContextList failed: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetErrorStatus("Query failed");
            }

            // Update service URLs combo box to remember any new
            // URL specified by the user
            UpdateUserServiceURL();

            SetStatus("Query completed");

            this.Cursor = Cursors.Default;

            return ctxList;
        }
        private void searchCLS(object sender, EventArgs e)
        {
            try
            {
                if (classificationTree.SelectedNode == null)
                {
                    SetErrorStatus("No node selected");
                    return;
                }
                TreeNode selectedNode = classificationTree.SelectedNode;
                QueryServiceManager.query query = new QueryServiceManager.query();
                query.resource = "openMDR-with-Classification";
                query.Items = new string[] { "*" };
                query.ItemsElementName = new global::QueryServiceControl.QueryServiceManager.ItemsChoiceType[]{
                    global::QueryServiceControl.QueryServiceManager.ItemsChoiceType.term };
                query.src = selectedNode.Tag.ToString();
                if (currentPageCLS == 0)
                {
                    query.startIndex = currentPageCLS;
                }
                else
                {
                    query.startIndex = currentPageCLS * pageSizeCLS;
                }
                query.numResults = pageSizeCLS + 1;

                lstClassificationQueryResult.Items.Clear();
                wbClassificationQueryResultDef.DocumentText = "";
                wbClassificationQueryResultValueDomain.DocumentText = "";

                SetStatus("Querying...");
                this.Cursor = Cursors.WaitCursor;
                btnCLSUse.Enabled = false;

                QueryServiceManager.QueryRequestQuery req = new global::QueryServiceControl.QueryServiceManager.QueryRequestQuery();
                req.query = query;
                lastClassificationQueryResult = qsm.query(req);

                if (lastClassificationQueryResult.Items.Length <= 0)
                {
                    SetStatus("No result");
                    this.Cursor = Cursors.Default;
                    return;
                }

                listResults(lastClassificationQueryResult.Items, lstClassificationQueryResult);
                if (lastClassificationQueryResult.Items.Length > 0)
                {
                    btnCLSUse.Enabled = true;
                }

                if (currentPageCLS > 0)
                {
                    btnBackCLS.Enabled = true;
                }

                if (lastClassificationQueryResult.Items.Length >= pageSizeCLS)
                {
                    btnForwardCLS.Enabled = true;
                }

                SetStatus("Query complete");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                SetErrorStatus("Query failed");
            }
            this.Cursor = Cursors.Default;
        }
        protected void search(object sender, EventArgs e)
        {
            try
            {
                if (txtTerm.Text == null || txtTerm.Text.Length == 0)
                {
                    SetErrorStatus("No search term.");
                    return;
                }

                setButtonsState(false);

                lstResults.Items.Clear();
                lstResults.Update();
                wbDetailsDef.DocumentText = "";
                wbDetailsPropsValues.DocumentText = "";
                wbOcProps.DocumentText = "";
                wbDetailsOther.DocumentText = "";

                SetStatus("Querying...Please wait...");
                this.Cursor = Cursors.WaitCursor;

                QueryServiceManager.QueryRequestQuery req = new global::QueryServiceControl.QueryServiceManager.QueryRequestQuery();
                req.query = new QueryServiceManager.query();
                req.query.resource = cbResources.SelectedValue.ToString();

                req.query.Items = new string[] { txtTerm.Text };

                if (cbSearchType.SelectedItem.Equals(TERM_SEARCH_TYPE)) {
                    req.query.ItemsElementName = new global::QueryServiceControl.QueryServiceManager.ItemsChoiceType[] {
                        global::QueryServiceControl.QueryServiceManager.ItemsChoiceType.term
                    };
                }
                else if (cbSearchType.SelectedItem.Equals(EXACTTERM_SEARCH_TYPE))
                {
                    req.query.ItemsElementName = new global::QueryServiceControl.QueryServiceManager.ItemsChoiceType[] {
                        global::QueryServiceControl.QueryServiceManager.ItemsChoiceType.exactTerm
                    };
                }
                else
                {
                    req.query.ItemsElementName = new global::QueryServiceControl.QueryServiceManager.ItemsChoiceType[] {
                        global::QueryServiceControl.QueryServiceManager.ItemsChoiceType.id
                    };
                }

                if (cbContextList.Text.Length > 0 && !cbContextList.Text.Equals("All"))
                {
                    req.query.queryFilter = new global::QueryServiceControl.QueryServiceManager.queryFilter();
                    req.query.queryFilter.context = cbContextList.Text;
                }

                if (currentPage == 0)
                {
                    req.query.startIndex = currentPage;
                }
                else
                {
                    req.query.startIndex = currentPage * pageSize;
                }
                req.query.numResults = pageSize + 1;

                qsm.Url = cbServiceUrls.Text;

                lastResult = qsm.query(req);
                if (lastResult == null || lastResult.Items == null || lastResult.Items.Length <= 0)
                {
                    SetStatus("No result");
                    this.Cursor = Cursors.Default;
                    return;
                }

                listResults(lastResult.Items, lstResults);
                if (lastResult.Items.Length >= pageSize)
                {
                    btnForward.Enabled = true;
                }

                btnUse.Enabled = true;
                btnAnnotate.Enabled = true;

                if (currentPage > 0)
                {
                    btnBack.Enabled = true;
                }

                SetStatus("Query completed");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Search failed: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetErrorStatus("Query failed");
            }
            this.Cursor = Cursors.Default;

            // Update service URLs combo box to remember any new
            // URL specified by the user
            UpdateUserServiceURL();
        }