Ejemplo n.º 1
0
        public Main(MainAdapter adapter)
        {
            InitializeComponent();
            Adapter = adapter;
            bsAdapter.DataSource     = Adapter;
            Adapter.PropertyChanged += Adapter_PropertyChanged;

            // add connections to the menu
            foreach (var c in Adapter.Project.Connections)
            {
                var m = new ConnectionMenuItem(c);
                m.Checked = c == Adapter.Project.CurrentConnection;
                m.Click  += (s, e) => Adapter.Project.CurrentConnection = c;
                connectionToolStripMenuItem.DropDownItems.Add(m);
            }
            Adapter.Project.CurrentConnectionChanged += (s, e) =>
            {
                foreach (ConnectionMenuItem c in connectionToolStripMenuItem.DropDownItems)
                {
                    c.Checked = (c.Connection == ((Project)s).CurrentConnection);
                }
            };

            // toolstrip combo has poor binding support so we need to wire it all up manually
            cboSearchFor.ComboBox.BindingContext = this.BindingContext;
            cboSearchFor.ComboBox.DataSource     = Adapter.SubjectSource;
            cboSearchFor.SelectedIndexChanged   += (s, e) => {
                Adapter.SelectedSubject = (ISubject)cboSearchFor.SelectedItem;
            };
            Adapter.SelectedSubjectChanged += (s, e) => {
                cboSearchFor.SelectedItem = Adapter.SelectedSubject;
            };

            Adapter.CurrentViewChanged += (s, e) =>
            {
                foreach (TabPage tp in tabControlParameters.TabPages)
                {
                    if (tp.Tag == Adapter.CurrentView)
                    {
                        tabControlParameters.SelectedTab = tp;
                        break;
                    }
                }
            };

            // update datagridview when new data arrives
            Adapter.Result.DataSourceChanged += (s, e) => {
                var data = ((DataTable)Adapter.Result.DataSource);
                if (data != null)
                {
                    foreach (DataGridViewColumn c in dataGridView1.Columns)
                    {
                        var path = (IFieldPath)data.Columns[c.DataPropertyName].ExtendedProperties["FieldPath"];
                        c.DefaultCellStyle.Format = path.Last.DisplayFormat;
                    }

                    dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
                    tabResults.Text = String.Concat("Results (", data.Rows.Count, ")");
                }
                else
                {
                    tabResults.Text = "Results";
                }

                // the hack to fix redraw on parameter views affects TabControl text update, so force refresh on change
                this.Refresh();
            };
        }
Ejemplo n.º 2
0
        public Main(MainAdapter adapter)
        {
            InitializeComponent();
            Adapter = adapter;
            bsAdapter.DataSource = Adapter;
            Adapter.PropertyChanged += Adapter_PropertyChanged;

            // add connections to the menu
            foreach (var c in Adapter.Project.Connections)
            {
                var m = new ConnectionMenuItem(c);
                m.Checked = c == Adapter.Project.CurrentConnection;
                m.Click += (s, e) => Adapter.Project.CurrentConnection = c;
                connectionToolStripMenuItem.DropDownItems.Add(m);
            }
            Adapter.Project.CurrentConnectionChanged += (s, e) =>
            {
                foreach (ConnectionMenuItem c in connectionToolStripMenuItem.DropDownItems)
                    c.Checked = (c.Connection == ((Project)s).CurrentConnection);
            };

            // toolstrip combo has poor binding support so we need to wire it all up manually
            cboSearchFor.ComboBox.BindingContext = this.BindingContext;
            cboSearchFor.ComboBox.DataSource = Adapter.SubjectSource;
            cboSearchFor.SelectedIndexChanged += (s, e) => {
                Adapter.SelectedSubject = (ISubject)cboSearchFor.SelectedItem;
            };
            Adapter.SelectedSubjectChanged += (s, e) => {
                cboSearchFor.SelectedItem = Adapter.SelectedSubject;
            };

            Adapter.CurrentViewChanged += (s, e) =>
            {
                foreach (TabPage tp in tabControlParameters.TabPages)
                {
                    if (tp.Tag == Adapter.CurrentView)
                    {
                        tabControlParameters.SelectedTab = tp;
                        break;
                    }
                }
            };

            // update datagridview when new data arrives
            Adapter.Result.DataSourceChanged += (s, e) => {
                var data = ((DataTable)Adapter.Result.DataSource);
                if (data != null)
                {
                    foreach (DataGridViewColumn c in dataGridView1.Columns)
                    {
                        var path = (IFieldPath)data.Columns[c.DataPropertyName].ExtendedProperties["FieldPath"];
                        c.DefaultCellStyle.Format = path.Last.DisplayFormat;
                    }

                    dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
                    tabResults.Text = String.Concat("Results (", data.Rows.Count, ")");
                }
                else
                {
                    tabResults.Text = "Results";
                }

                // the hack to fix redraw on parameter views affects TabControl text update, so force refresh on change
                this.Refresh();
            };
        }