Example #1
0
        public ImportDatabaseForm(
            nHydrateModel model,
            nHydrate.DataImport.Database currentDatabase,
            Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
            : this()
        {
            _model = model;
            this.CurrentDatabase = currentDatabase;

            this.DatabaseConnectionControl1.FileName = Path.Combine((new FileInfo(docData.FileName)).DirectoryName, "importconnection.cache");

            tvwAdd.AfterCheck     += new TreeViewEventHandler(treeView1_AfterCheck);
            tvwRefresh.AfterCheck += new TreeViewEventHandler(treeView1_AfterCheck);
            tvwDelete.AfterCheck  += new TreeViewEventHandler(treeView1_AfterCheck);

            //tvwAdd.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
            //tvwRefresh.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
            //tvwDelete.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);

            wizard1.BeforeSwitchPages   += new nHydrate.Wizard.Wizard.BeforeSwitchPagesEventHandler(wizard1_BeforeSwitchPages);
            wizard1.AfterSwitchPages    += new nHydrate.Wizard.Wizard.AfterSwitchPagesEventHandler(wizard1_AfterSwitchPages);
            wizard1.Finish              += new EventHandler(wizard1_Finish);
            wizard1.FinishEnabled        = false;
            chkSettingPK.CheckedChanged += new EventHandler(chkSettingPK_CheckedChanged);
            cmdTestConnection.Click     += new EventHandler(cmdTestConnection_Click);

            this.Settings = new ImportModelSettings();
            this.Settings.OverridePrimaryKey = chkSettingPK.Checked;

            DatabaseConnectionControl1.LoadSettings();

            EnableButtons();
        }
Example #2
0
        //private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        //{
        //  var d = e.Node.Tag as DataTreeItem;
        //  if (d == null) txtChanged.Text = "";
        //  else txtChanged.Text = d.GetChangeText();
        //}

        private void wizard1_BeforeSwitchPages(object sender, nHydrate.Wizard.Wizard.BeforeSwitchPagesEventArgs e)
        {
            if (wizard1.WizardPages[e.OldIndex] == pageConnection)
            {
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    DatabaseConnectionControl1.PersistSettings();
                    var connectionString = DatabaseConnectionControl1.ImportOptions.GetConnectionString();
                    var schemaModelHelper = new nHydrate.DataImport.SqlClient.SchemaModelHelper();

                    if (!schemaModelHelper.IsValidConnectionString(connectionString))
                    {
                        this.Cursor = Cursors.Default;
                        e.Cancel = true;
                        MessageBox.Show("This not a valid connection string!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //Setup new model
                    var project = new nHydrate.DataImport.Database();
                    var auditFields = new List<SpecialField>();
                    auditFields.Add(new SpecialField { Name = _model.CreatedByColumnName, Type = SpecialFieldTypeConstants.CreatedBy });
                    auditFields.Add(new SpecialField { Name = _model.CreatedDateColumnName, Type = SpecialFieldTypeConstants.CreatedDate });
                    auditFields.Add(new SpecialField { Name = _model.ModifiedByColumnName, Type = SpecialFieldTypeConstants.ModifiedBy });
                    auditFields.Add(new SpecialField { Name = _model.ModifiedDateColumnName, Type = SpecialFieldTypeConstants.ModifedDate });
                    auditFields.Add(new SpecialField { Name = _model.TimestampColumnName, Type = SpecialFieldTypeConstants.Timestamp });
                    auditFields.Add(new SpecialField { Name = _model.TenantColumnName, Type = SpecialFieldTypeConstants.Tenant });

                    var pkey = ProgressHelper.ProgressingStarted("Importing...", true);
                    try
                    {
                        var importDomain = new nHydrate.DataImport.SqlClient.ImportDomain();

                        this.NewDatabase = importDomain.Import(connectionString, auditFields);
                        this.NewDatabase.CleanUp();
                        this.NewDatabase.SetupIdMap(this.CurrentDatabase);
                        //nHydrate.DataImport.ImportDomain.ReMapIDs(this.CurrentDatabase, this.NewDatabase);

                        //Remove tenant views
                        NewDatabase.ViewList.Remove(x => x.Name.ToLower().StartsWith(_model.TenantPrefix.ToLower() + "_"));

                        var errorCount = NewDatabase.StoredProcList.Count(x => x.InError);
                        NewDatabase.StoredProcList.Remove(x => x.InError);

                        //Load the tree
                        this.Populate();

                        ProgressHelper.ProgressingComplete(pkey);
                        if (errorCount > 0)
                            MessageBox.Show("There were " + errorCount + " stored procedure(s) that could not be imported.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                    finally
                    {
                        ProgressHelper.ProgressingComplete(pkey);
                    }

                    if (!this.AreChanges())
                    {
                        this.Cursor = Cursors.Default;
                        e.Cancel = true;
                        MessageBox.Show("This modelRoot is up-to-date. There are no changes to refresh.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                }
                catch (Exception ex)
                {
                    throw;
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
            else if (wizard1.WizardPages[e.OldIndex] == pageConnection && wizard1.WizardPages[e.NewIndex] == pageEntities)
            {
            }
            else if (wizard1.WizardPages[e.OldIndex] == pageEntities && wizard1.WizardPages[e.NewIndex] == pageSummary)
            {
                //If there are no entities selected and relations are still checked then prompt
                var nodeCheckedList = tvwAdd.Nodes[0].Nodes.AsEnumerable<TreeNode>().Where(x => x.Checked).ToList();
                nodeCheckedList.AddRange(tvwRefresh.Nodes[0].Nodes.AsEnumerable<TreeNode>().Where(x => x.Checked).ToList());
                nodeCheckedList.AddRange(tvwDelete.Nodes[0].Nodes.AsEnumerable<TreeNode>().Where(x => x.Checked).ToList());

                if (nodeCheckedList.Count == 0 && !chkIgnoreRelations.Checked)
                {
                    var result = MessageBox.Show("There are no entities selected but relations will be refreshed. Do you want to turn off relation refreshing?", "Ignore Relations", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        chkIgnoreRelations.Checked = true;
                    }
                    else if (result == System.Windows.Forms.DialogResult.No)
                    {
                        //Do Nothing
                    }
                    else if (result == System.Windows.Forms.DialogResult.Cancel)
                    {
                        e.Cancel = true;
                        return;
                    }
                }

                //Moving the to the summary page
                CreateSummary();
            }

        }