Ejemplo n.º 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();

            connection.DBMode = "DEBUG";
            switch (connection.ShowDialog())
            {
            case DialogResult.OK: {
                bool _thecombinationexists = false;
                for (int i = 0; i < lvwConnections.Items.Count; i++)
                {
                    if (
                        (lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBServerType].Text == connection.DBServerType.ToString())
                        &&
                        (lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBMode].Text == connection.DBMode)
                        )
                    {
                        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
                            )
                        {
                            lvwConnections.Items[i].SubItems[(int)eConnectionColumns.Default].Text            = string.Empty;
                            lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBServerType].Text       = connection.DBServerType.ToString();
                            lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBMode].Text             = connection.DBMode;
                            lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBConnectionstring].Text = connection.DBConnectionstring;
                        }
                        _thecombinationexists = true;
                        break;                                 // no need to keep searching, combination has been found...
                    }
                }
                if (!_thecombinationexists)
                {
                    lvwConnections.Items.Add(
                        new ListViewItem(
                            new string[] {
                            (lvwConnections.Items.Count == 0) ? "*" : string.Empty,
                            connection.DBServerType.ToString(),
                            connection.DBMode,
                            connection.DBConnectionstring
                        }
                            )
                        );
                }
                break;
            }

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

								&&
								(i != 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:
									lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.Default].Text 
										= lvwConnections.Items[i].SubItems[(int)eConnectionColumns.Default].Text ;

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

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

							// update other properties:
							lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBServerType].Text = connection.DBServerType.ToString();
							lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBMode].Text = connection.DBMode;
							lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBConnectionstring].Text = connection.DBConnectionstring;
						}
						break;
					}
					case DialogResult.Cancel: {
						break;
					}
				}
			}
		}
		//#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();
			connection.DBMode = "DEBUG";
			switch (connection.ShowDialog()) {
				case DialogResult.OK: {
					bool _thecombinationexists = false;
					for (int i = 0; i < lvwConnections.Items.Count; i++) {
						if (
							(lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBServerType].Text == connection.DBServerType.ToString())
							&&
							(lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBMode].Text == connection.DBMode)
						) {
							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
							) {
								lvwConnections.Items[i].SubItems[(int)eConnectionColumns.Default].Text = string.Empty;
								lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBServerType].Text = connection.DBServerType.ToString();
								lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBMode].Text = connection.DBMode;
								lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBConnectionstring].Text = connection.DBConnectionstring;
							}
							_thecombinationexists = true;
							break; // no need to keep searching, combination has been found...
						}
					}
					if (!_thecombinationexists) {
						lvwConnections.Items.Add(
							new ListViewItem(
								new string[] {
									(lvwConnections.Items.Count == 0) ? "*" : string.Empty, 
									connection.DBServerType.ToString(), 
									connection.DBMode,
									connection.DBConnectionstring
								}
							)
						);
					}
					break;
				}
				case DialogResult.Cancel: {
					break;
				}
			}
		}
Ejemplo n.º 4
0
        private void btnEdit_Click(object sender, System.EventArgs e)
        {
            if (lvwConnections.SelectedItems.Count == 1)
            {
                frmConnectionstring connection = new frmConnectionstring();
                connection.DBServerType = (DBServerTypes)Enum.Parse(
                    typeof(DBServerTypes),
                    lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBServerType].Text
                    );
                connection.DBMode             = lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBMode].Text;
                connection.DBConnectionstring = lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.DBConnectionstring].Text;
                switch (connection.ShowDialog())
                {
                case DialogResult.OK: {
                    bool _samecombinationalreadyexists = false;
                    for (int i = 0; i < lvwConnections.Items.Count; i++)
                    {
                        if (
                            (lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBServerType].Text == connection.DBServerType.ToString())
                            &&
                            (lvwConnections.Items[i].SubItems[(int)eConnectionColumns.DBMode].Text == connection.DBMode)

                            &&
                            (i != 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:
                                lvwConnections.SelectedItems[0].SubItems[(int)eConnectionColumns.Default].Text
                                    = lvwConnections.Items[i].SubItems[(int)eConnectionColumns.Default].Text;

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

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

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

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