Beispiel #1
0
        //#endregion

        //#region Events...
        #region private void btnNew_Click(object sender, System.EventArgs e);
        private void btnNew_Click(object sender, System.EventArgs e)
        {
            frmConnectionstring connection = new frmConnectionstring();

            switch (connection.ShowDialog())
            {
            case DialogResult.OK: {
                bool _thecombinationexists = false;
                for (int i = 0; i < this.lvwConnections.Items.Count; i++)
                {
                    if (
                        string.Compare(
                            this.lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBServerType].Text,
                            connection.DBServerType.ToString(),
                            false,
                            System.Globalization.CultureInfo.CurrentCulture
                            ) == 0
                        )
                    {
                        if (
                            System.Windows.Forms.MessageBox.Show(
                                "such combination exists, overwrite it?",
                                "combination exists",
                                System.Windows.Forms.MessageBoxButtons.OKCancel,
                                System.Windows.Forms.MessageBoxIcon.Warning
                                ) != System.Windows.Forms.DialogResult.Cancel
                            )
                        {
                            this.lvwConnections.Items[i].SubItems[(int)eConnectionColumns.Default].Text            = string.Empty;
                            this.lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBServerType].Text       = connection.DBServerType.ToString();
                            this.lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBConnectionstring].Text = connection.DBConnectionstring;
                        }
                        _thecombinationexists = true;
                        break;                                 // no need to keep searching, combination has been found...
                    }
                }
                if (!_thecombinationexists)
                {
                    this.lvwConnections.Items.Add(
                        new ListViewItem(
                            new string[] {
                            (this.lvwConnections.Items.Count == 0) ? "*" : string.Empty,
                            connection.DBServerType.ToString(),
                            connection.DBConnectionstring
                        }
                            )
                        );
                }
                break;
            }

            case DialogResult.Cancel: {
                break;
            }
            }
        }
Beispiel #2
0
        private void btnEdit_Click(object sender, System.EventArgs e)
        {
            if (this.lvwConnections.SelectedItems.Count == 1)
            {
                frmConnectionstring connection = new frmConnectionstring();
                connection.DBServerType = (DBServerTypes)Enum.Parse(
                    typeof(DBServerTypes),
                    this.lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBServerType].Text
                    );
                connection.DBConnectionstring = this.lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBConnectionstring].Text;
                switch (connection.ShowDialog())
                {
                case DialogResult.OK: {
                    bool _samecombinationalreadyexists = false;
                    for (int i = 0; i < this.lvwConnections.Items.Count; i++)
                    {
                        if (
                            (this.lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBServerType].Text == connection.DBServerType.ToString())

                            &&
                            (i != this.lvwConnections.SelectedItems[0].Index)
                            )
                        {
                            if (
                                System.Windows.Forms.MessageBox.Show(
                                    "such combination exists, overwrite it?",
                                    "combination exists",
                                    System.Windows.Forms.MessageBoxButtons.OKCancel,
                                    System.Windows.Forms.MessageBoxIcon.Warning
                                    ) != System.Windows.Forms.DialogResult.Cancel
                                )
                            {
                                // leave it as it is:
                                this.lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.Default].Text
                                    = this.lvwConnections.Items[i].SubItems[(int)eConnectionColumns.Default].Text;

                                // update other properties:
                                this.lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBServerType].Text       = connection.DBServerType.ToString();
                                this.lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBConnectionstring].Text = connection.DBConnectionstring;

                                this.lvwConnections.Items.RemoveAt(i);
                            }
                            _samecombinationalreadyexists = true;
                            break;                                     // no need to keep searching, combination has been found...
                        }
                    }
                    if (!_samecombinationalreadyexists)
                    {
                        // leave it as it is:
                        //this.lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.Default].Text = string.Empty;

                        // update other properties:
                        this.lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBServerType].Text       = connection.DBServerType.ToString();
                        this.lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBConnectionstring].Text = connection.DBConnectionstring;
                    }
                    break;
                }

                case DialogResult.Cancel: {
                    break;
                }
                }
            }
        }