/// <summary>
        /// Event delegate method fired when the <see cref="RenameMappingButton"/> button is clicked.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void RenameMappingButton_Click(object sender, EventArgs e)
        {
            if (_selectedMapping == null)
            {
                return;
            }

            int    indexForName = 1;
            string proposedMappingName;

            do
            {
                proposedMappingName = _selectedMapping.TableName + "Mapping" + (indexForName > 1 ? indexForName.ToString(CultureInfo.InvariantCulture) : string.Empty);
                indexForName++;
            }while (Mappings.Any(mapping => mapping.Name == proposedMappingName));

            string newName;

            using (var newColumnMappingDialog = new AppendNewColumnMappingDialog(proposedMappingName))
            {
                DialogResult dr = newColumnMappingDialog.ShowDialog();
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                MappingsChanged = true;
                newName         = newColumnMappingDialog.ColumnMappingName;
            }

            // Show error if name already exists
            if (Mappings.Count(t => string.Compare(t.Name, newName, StringComparison.InvariantCultureIgnoreCase) == 0) > 0)
            {
                MiscUtilities.ShowCustomizedErrorDialog(Resources.MappingNameAlreadyExistsTitle, Resources.MappingNameAlreadyExistsDetail);
                return;
            }

            _selectedMapping.Name = newName;
            RefreshMappingList();
            ListViewItem item = MappingsListView.FindItemWithText(string.Format("{0} ({1}.{2})", newName, _selectedMapping.SchemaName, _selectedMapping.TableName));

            if (item != null)
            {
                MappingsListView.Items[item.Index].Selected = true;
            }

            MappingsListView.Focus();
        }
예제 #2
0
        /// <summary>
        /// Event delegate method fired when the <see cref="RenameMappingButton"/> button is clicked.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void RenameMappingButton_Click(object sender, EventArgs e)
        {
            if (_selectedMapping == null)
            {
                return;
            }

            string newName;

            using (var newColumnMappingDialog = new AppendNewColumnMappingDialog(Mappings, _selectedMapping.TableName))
            {
                var dr = newColumnMappingDialog.ShowDialog();
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                newName = newColumnMappingDialog.ColumnMappingName;
                if (string.IsNullOrEmpty(newName))
                {
                    // Should not get to this part of the code, if this is reached it means there is an issue in the logic above generating a mapping name.
                    MiscUtilities.ShowCustomizedErrorDialog("Error", Resources.AppendColumnMappingEmptyError);
                    return;
                }

                if (string.Equals(_selectedMapping.Name, newName, StringComparison.OrdinalIgnoreCase))
                {
                    // User input exactly the same name, so no renaming was actually done.
                    return;
                }

                MappingsChanged = true;
            }

            _selectedMapping.Name = newName;
            RefreshMappingList();
            var item = MappingsListView.FindItemWithText($"{newName} ({_selectedMapping.SchemaName}.{_selectedMapping.TableName})");

            if (item != null)
            {
                MappingsListView.Items[item.Index].Selected = true;
            }

            MappingsListView.Focus();
        }