Exemplo n.º 1
0
        private void ChangeConnection(Button button, ProjectConnection connection, string title)
        {
            var builder = new SqlConnectionStringBuilder(connection.ConnectionString);

            using (var selector = new DbSelectForm())
            {
                selector.Text     = title;
                selector.User     = builder.IntegratedSecurity ? "" : builder.UserID;
                selector.Server   = builder.DataSource;
                selector.Database = builder.InitialCatalog;
ShowSelector:
                if (selector.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if (CompareProject.Type == ProjectType.Monitor)
                {
                    if (!Environment.MachineName.Equals(selector.HostName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        MessageBox.Show("For monitoring projects, server must be on the same machine where DBCompare is running.\nThis is for backup and restore purposes.", "Invalid server", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        goto ShowSelector;
                    }
                }
                connection.ConnectionString = selector.ConnectionString;
            }
            FillConnectionButton(button, connection);
        }
Exemplo n.º 2
0
        public bool CreateNewProject(ProjectType type)
        {
            if (IsDirty)
            {
                if (!SaveCurrent())
                {
                    return(false);
                }
            }
            var project = new DataCompareProject();

            project.Type = type;
            using (var selector = new DbSelectForm())
            {
                selector.Text = type == ProjectType.Compare ? "Select Database A" : "Select Source Database";

                selector.OkButtonText  = "Next";
                selector.OkButtonImage = DBCompare.Properties.Resources.Right;
ShowSelector:
                if (selector.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return(false);
                }
                if (type == ProjectType.Monitor)
                {
                    if (!Environment.MachineName.Equals(selector.HostName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        MessageBox.Show("For monitoring projects, server must be on the same machine where DBCompare is running.\nThis is for backup and restore purposes.", "Invalid server", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        goto ShowSelector;
                    }
                }
                project.SetConnectionA(selector.ConnectionString);
            }
            if (type == ProjectType.Compare)
            {
                using (var selector = new DbSelectForm())
                {
                    selector.Text = "Select Database B";
                    if (selector.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return(false);
                    }
                    project.SetConnectionB(selector.ConnectionString);
                }
            }
            else
            {
                using (var backupRestore = new BackupRestoreForm(project))
                {
                    if (backupRestore.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return(false);
                    }
                }
            }
            return(ShowProject(project));
        }