Example #1
0
        public DataSourcePicker()
        {
            InitializeComponent();
            try
            {
                _tbSql.Font = MainForm.TheMainForm._scriptEditorFont;
            }
            catch { }

            var tooltip = MainForm.TheMainForm as ITooltipService;

            if (tooltip != null)
            {
                tooltip.SetToolTip(this._btnEditConnection, Strings.DataSourcePicker.TtipBtnEditConnection);
                tooltip.SetToolTip(this._btnDataSourceProperties, Strings.DataSourcePicker.TtipBtnDataSourceProperties);
            }

            // Fill _cbDataProvider
            foreach (DsgnDataLinkBase dl in DsgnDataLinkBase.Links)
            {
                _cbDataProvider.Items.Add(new DataProviderDesc(dl));
            }

            // Fill _cbConnectionString
            ArrayList connections = AppSettings.LoadList("recentconnections", MessageForm.Warn);

            foreach (string s in connections)
            {
                _cbConnectionString.Items.Add(ConnectionDesc.FromSettingsString(s));
            }

            _lastSelectedDataTab = _tpConnection;
        }
Example #2
0
        // Updates list of available datasources (tables, views, stored procs)
        // for connection string specified by _cbDataProvider, _cbConnectionString
        // selects specified recordSource if possible
        private void ConnectionStringChanged(
            string recordSource)
        {
            // store current value of connection string to prevent update when
            // _cbConnectionString lost focus
            _oldConnectionString = _cbConnectionString.Text;

            BeginUpdate();
            Cursor = Cursors.WaitCursor;
            try
            {
                DsgnDataLinkBase dl = ((DataProviderDesc)_cbDataProvider.SelectedItem).Link;
                _tvDataSource.Nodes.Clear();
                if (!string.IsNullOrEmpty(_cbConnectionString.Text) && dl.Available)
                {
                    if (dl.UpdateControls(this, recordSource))
                    {
                        // current connection string should be stored in MRU list
                        int i = IndexOfConnectionDesc(dl, _cbConnectionString.Text);
                        if (i >= 0)
                        {
                            ConnectionDesc ci = (ConnectionDesc)_cbConnectionString.Items[i];
                            _cbConnectionString.Items.Remove(ci);
                            _cbConnectionString.Items.Insert(0, ci);
                            _cbConnectionString.SelectedIndex = 0;
                        }
                        else
                        {
                            if (_cbConnectionString.Items.Count > c_MaxMRUSize)
                            {
                                _cbConnectionString.Items.RemoveAt(_cbConnectionString.Items.Count - 1);
                            }
                            _cbConnectionString.Items.Add(new ConnectionDesc(dl, _cbConnectionString.Text));
                        }
                        // save MRU connections to application's settings
                        // SaveList uses ToString() method of objects in list so we can
                        // simple pass _cbConnectionString.Items items will be automatically converted to string like:
                        // OLEDB;Data source=...
                        List <string> l = new List <string>();
                        foreach (ConnectionDesc cd in _cbConnectionString.Items)
                        {
                            l.Add(cd.ToSettingsString());
                        }
                        AppSettings.SaveList("recentconnections", l, true, MessageForm.Warn);
                    }
                }
                UpdateButtons();
            }
            finally
            {
                Cursor = Cursors.Default;
                EndUpdate();
            }
        }
Example #3
0
 private int IndexOfConnectionDesc(
     DsgnDataLinkBase dataLink,
     string connectionString)
 {
     for (int i = 0; i < _cbConnectionString.Items.Count; i++)
     {
         ConnectionDesc cd = (ConnectionDesc)_cbConnectionString.Items[i];
         if (cd.Link == dataLink && cd.ConnectionString == connectionString)
         {
             return(i);
         }
     }
     return(-1);
 }
Example #4
0
        private void _cbConnectionString_DrawItem(object sender, DrawItemEventArgs e)
        {
            //
            ConnectionDesc cd = (ConnectionDesc)_cbConnectionString.Items[e.Index];

            e.DrawBackground();
            Color color = ((e.State & DrawItemState.Selected) != 0) ? SystemColors.HighlightText : SystemColors.WindowText;

            using (Font f = new Font(_cbConnectionString.Font, FontStyle.Bold))
            {
                Size      sz          = TextRenderer.MeasureText(e.Graphics, cd.Caption, f, Size.Empty, TextFormatFlags.Default);
                Rectangle captionRect = new Rectangle(e.Bounds.X + c_ConnectionDrawLeftOffset, e.Bounds.Y, sz.Width, e.Bounds.Height);
                Rectangle detailsRect = new Rectangle(e.Bounds.X + sz.Width + c_ConnectionDrawLeftOffset + c_ConnectionDrawSpacing, e.Bounds.Y, e.Bounds.Width - sz.Width - c_ConnectionDrawLeftOffset - c_ConnectionDrawSpacing, e.Bounds.Height);
                TextRenderer.DrawText(e.Graphics, cd.Caption, f, captionRect, color, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                TextRenderer.DrawText(e.Graphics, cd.Details, _cbConnectionString.Font, detailsRect, color, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.PathEllipsis);
            }
            e.DrawFocusRectangle();
        }
Example #5
0
        private void _cbConnectionString_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Updating)
            {
                return;
            }

            ConnectionDesc cd = _cbConnectionString.SelectedItem as ConnectionDesc;

            if (cd != null)
            {
                BeginUpdate();
                foreach (DataProviderDesc dpd in _cbDataProvider.Items)
                {
                    if (dpd.Link == cd.Link)
                    {
                        _cbDataProvider.SelectedItem = dpd;
                        break;
                    }
                }
                ConnectionStringChanged(RecordSource);
                EndUpdate();
            }
        }