Exemplo n.º 1
0
        private void StoreFieldDefs()
        {
            if (_actTableNode == null)
            {
                return;
            }

            QueryTheme theme = _actTableNode.Parent as QueryTheme;

            if (theme == null || theme.PromptDef == null)
            {
                return;
            }


            DataTable table = _actTableNode.QueryFieldDef;

            table.Rows.Clear();

            for (int i = 0; i < dgLayers.Rows.Count - 1; i++)
            {
                DataGridViewRow dgRow = dgLayers.Rows[i];

                DataRow[] rows = theme.PromptDef.Select("Prompt='" + dgRow.Cells[1].Value + "'");
                if (rows.Length == 0)
                {
                    continue;
                }

                table.Rows.Add(
                    new object[] { dgRow.Cells[0].Value, rows[0]["ID"], dgRow.Cells[2].Value });
            }

            IFeatureLayer fLayer = _actTableNode.GetLayer(_doc) as IFeatureLayer;

            if (fLayer != null && fLayer.Fields != null && _actTableNode.VisibleFieldDef != null)
            {
                _actTableNode.VisibleFieldDef.UseDefault          = chkUseStandard.Checked;
                _actTableNode.VisibleFieldDef.PrimaryDisplayField = cmbPrimaryField.Text;

                table = _actTableNode.VisibleFieldDef;
                table.Rows.Clear();
                foreach (IField field in fLayer.Fields.ToEnumerable())
                {
                    for (int i = 0; i < dgVisibleFields.Rows.Count; i++)
                    {
                        if ((string)dgVisibleFields.Rows[i].Cells[1].Value == field.name &&
                            ((string)dgVisibleFields.Rows[i].Cells[2].Value != field.aliasname ||
                             (bool)dgVisibleFields.Rows[i].Cells[0].Value == true))
                        {
                            table.Rows.Add(
                                new object[] { (bool)dgVisibleFields.Rows[i].Cells[0].Value, field.name, (string)dgVisibleFields.Rows[i].Cells[2].Value });
                        }
                    }
                }
            }
            _actTableNode = null;
        }
Exemplo n.º 2
0
        private void treeQueries_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            QueryTheme node = treeQueries.GetNodeAt(e.X, e.Y) as QueryTheme;

            if (node != null && node.Type == QueryTheme.NodeType.query)
            {
                node.Expand();
                node.BeginEdit();
            }
        }
Exemplo n.º 3
0
        private void BuildQueryForm()
        {
            panelCustomFields.Controls.Clear();
            if (_combo == null)
            {
                return;
            }

            QueryTheme query = GetQueryTheme(_combo.Text);

            if (query == null)
            {
                return;
            }

            lblQueryName.Text = query.Text;
            if (query.PromptDef == null)
            {
                return;
            }

            int y = 5;

            foreach (DataRow row in query.PromptDef.Rows)
            {
                System.Windows.Forms.Label label = new System.Windows.Forms.Label();
                label.Text      = row["Prompt"].ToString() + ":" + (((bool)row["Obliging"]) ? "*" : "  ");
                label.Location  = new System.Drawing.Point(10, y);
                label.Size      = new Size(150, 21);
                label.TextAlign = ContentAlignment.MiddleRight;
                panelCustomFields.Controls.Add(label);

                Control txtBox = CustomInputControl.Create(row);
                if (txtBox == null)
                {
                    continue;
                }

                txtBox.Location = new System.Drawing.Point(163, y);
                txtBox.Size     = new Size(190, 21);
                txtBox.Name     = "txt" + row["ID"].ToString();
                panelCustomFields.Controls.Add(txtBox);
                y += 26;
            }
        }
Exemplo n.º 4
0
        public void Load(IPersistStream stream)
        {
            if (_queries == null)
            {
                _queries = new List <QueryTheme>();
            }

            _queries.Clear();
            while (true)
            {
                QueryTheme theme = stream.Load("Query", null, new QueryTheme()) as QueryTheme;
                if (theme == null)
                {
                    break;
                }

                _queries.Add(theme);
            }
        }
Exemplo n.º 5
0
        private void btnAddTable_Click(object sender, EventArgs e)
        {
            QueryTheme parent = treeQueries.SelectedNode as QueryTheme;

            if (parent == null)
            {
                return;
            }

            FormSelectLayer selLayer = new FormSelectLayer(_doc);

            if (selLayer.ShowDialog() == DialogResult.OK)
            {
                if (selLayer.SelectedLayer == null)
                {
                    return;
                }

                QueryThemeTable node = new QueryThemeTable(selLayer.SelectedLayer, selLayer.SelectedLayerAlias);
                parent.Nodes.Add(node);
                parent.Expand();
            }
        }
Exemplo n.º 6
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            if (_parent == null || _combo == null)
            {
                return;
            }

            if (_combo.ThemeMode == QueryThemeMode.Default)
            {
                _queryVal   = cmbQueryText.Text;
                _queryField = cmbField.SelectedItem != null?cmbField.SelectedItem.ToString() : "";

                _useWildcards = chkWildcards.Checked;
                _focusMap     = _parent._doc != null ? _parent._doc.FocusMap : null;
                _mode         = _parent.Mode;

                if (btnAllFields.Checked)
                {
                    _searchType = SearchType.allfields;
                }
                else if (btnField.Checked)
                {
                    _searchType = SearchType.field;
                }
                else if (btnDisplayField.Checked)
                {
                    _searchType = SearchType.displayfield;
                }
                else
                {
                    return;
                }

                if (!cmbQueryText.Items.Contains(_queryVal))
                {
                    cmbQueryText.Items.Add(_queryVal);
                }

                _cancelTracker.Reset();
                btnQuery.Enabled = false;
                btnStop.Enabled  = true;
                _worker.RunWorkerAsync(_parent.AllQueryableLayers);
            }
            else
            {
                if (_combo.UserDefinedQueries == null)
                {
                    return;
                }
                foreach (QueryTheme theme in _combo.UserDefinedQueries.Queries)
                {
                    if (theme.Text == lblQueryName.Text)
                    {
                        if (theme.PromptDef == null)
                        {
                            return;
                        }
                        _userdefValues = new Dictionary <int, string>();
                        foreach (DataRow row in theme.PromptDef.Rows)
                        {
                            foreach (Control ctrl in panelCustomFields.Controls)
                            {
                                if (ctrl.Name == "txt" + row["ID"].ToString())
                                {
                                    _userdefValues.Add((int)row["ID"], ctrl.Text);
                                }
                            }
                        }
                        _theme    = theme;
                        _focusMap = _parent._doc != null ? _parent._doc.FocusMap : null;

                        _cancelTracker.Reset();
                        btnQuery.Enabled = false;
                        btnStop.Enabled  = true;
                        _worker2.RunWorkerAsync();
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void btnAddSeperator_Click(object sender, EventArgs e)
        {
            QueryTheme node = new QueryTheme();

            treeQueries.Nodes.Add(node);
        }
Exemplo n.º 8
0
        private void btnAddQuery_Click(object sender, EventArgs e)
        {
            QueryTheme node = new QueryTheme("Query" + (treeQueries.Nodes.Count + 1).ToString());

            treeQueries.Nodes.Add(node);
        }
Exemplo n.º 9
0
        private void treeQueries_AfterSelect(object sender, TreeViewEventArgs e)
        {
            btnAddTable.Enabled      = treeQueries.SelectedNode is QueryTheme && ((QueryTheme)treeQueries.SelectedNode).Type == QueryTheme.NodeType.query;
            tabControlLayers.Visible = treeQueries.SelectedNode is QueryThemeTable;
            dgQueries.Visible        = treeQueries.SelectedNode is QueryTheme;

            TreeNode node = treeQueries.SelectedNode;

            if (node is QueryTheme)
            {
                StoreFieldDefs();
                DataTable tab = ((QueryTheme)node).PromptDef;

                dgQueries.DataSource = tab;
            }
            else if (node is QueryThemeTable)
            {
                #region Query Fields
                StoreFieldDefs();
                dgLayers.Rows.Clear();

                IFeatureLayer layer = ((QueryThemeTable)node).GetLayer(_doc) as IFeatureLayer;
                if (layer != null)
                {
                    colField.Items.Clear();
                    if (layer.Fields != null)
                    {
                        foreach (IField field in layer.Fields.ToEnumerable())
                        {
                            colField.Items.Add(field.name);
                        }
                    }
                }
                QueryTheme theme = node.Parent as QueryTheme;
                if (theme == null && theme.PromptDef == null)
                {
                    return;
                }

                colPrompt.Items.Clear();
                foreach (DataRow row in theme.PromptDef.Select())
                {
                    colPrompt.Items.Add(row["Prompt"].ToString());
                }

                foreach (DataRow row in ((QueryThemeTable)node).QueryFieldDef.Rows)
                {
                    try
                    {
                        string field    = row["Field"].ToString();
                        string op       = row["Operator"].ToString();
                        int    promptID = (int)row["Prompt"];

                        if (colField.Items.IndexOf(field) == -1)
                        {
                            field = "";
                        }
                        if (colOperator.Items.IndexOf(op) == -1)
                        {
                            op = "";
                        }
                        DataRow[] rows = theme.PromptDef.Select("ID=" + promptID);
                        if (rows.Length == 0)
                        {
                            continue;
                        }

                        dgLayers.Rows.Add(
                            new object[] { field, rows[0]["Prompt"], op });
                    }
                    catch { }
                }
                #endregion

                #region Visible Fields
                if (((QueryThemeTable)node).VisibleFieldDef != null && layer != null && layer.Fields != null)
                {
                    QueryThemeVisibleFieldDef visFields = ((QueryThemeTable)node).VisibleFieldDef;

                    chkUseStandard.Checked = visFields.UseDefault;

                    cmbPrimaryField.Items.Clear();
                    dgVisibleFields.Rows.Clear();

                    foreach (IField field in layer.Fields.ToEnumerable())
                    {
                        cmbPrimaryField.Items.Add(field.name);
                        if (field.name == visFields.PrimaryDisplayField ||
                            (visFields.PrimaryDisplayField == "" &&
                             layer.Fields.PrimaryDisplayField != null &&
                             field.name == layer.Fields.PrimaryDisplayField.name))
                        {
                            cmbPrimaryField.SelectedIndex = cmbPrimaryField.Items.Count - 1;
                        }

                        DataRow[] r = visFields.Select("Name='" + field.name + "'");
                        if (r.Length == 1)
                        {
                            dgVisibleFields.Rows.Add(new object[] { (bool)r[0]["Visible"], field.name, (string)r[0]["Alias"], field.type.ToString() });
                        }
                        else
                        {
                            dgVisibleFields.Rows.Add(new object[] { false, field.name, field.aliasname, field.type.ToString() });
                        }
                    }
                }
                #endregion

                _actTableNode = node as QueryThemeTable;
            }
        }