Exemplo n.º 1
0
        private void wizard1_Finish(object sender, EventArgs e)
        {
            DatabaseConnectionControl1.PersistSettings();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        private void wizard1_Finish(object sender, EventArgs e)
        {
            DatabaseConnectionControl1.PersistSettings();

            _currentTable.StaticData.Clear();
            var dt = (System.Data.DataTable) this.dataGridView1.DataSource;

            foreach (System.Data.DataRow dr in dt.Rows)
            {
                var rowEntry   = new RowEntry(_currentTable.Root);
                var columnList = _currentTable.GetColumns().ToList();
                for (var ii = 0; ii < columnList.Count; ii++)
                {
                    var cellEntry = new CellEntry(_currentTable.Root);
                    cellEntry.ColumnRef = columnList[ii].CreateRef();
                    //if (dr[ii].GetType().ToString() == "System.Byte[]")
                    //{
                    //  cellEntry.Value = System.Text.ASCIIEncoding.ASCII.GetString((byte[])dr[ii]);
                    //}
                    //else
                    //{
                    cellEntry.Value = dr[ii].ToString();
                    //}
                    rowEntry.CellEntries.Add(cellEntry);
                }
                _currentTable.StaticData.Add(rowEntry);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 4
0
        private void ApplyChanges()
        {
            //Save the actual item
            using (var transaction = _store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
            {
                #region Entity
                if (_modelElement is nHydrate.Dsl.Entity)
                {
                    var targetItem = _modelElement as nHydrate.Dsl.Entity;
                    var importItem = _importDomain.GetEntity(DatabaseConnectionControl1.ImportOptions.GetConnectionString(), (string)cboItem.SelectedItem, _auditFields);
                    targetItem.AllowCreateAudit = importItem.AllowCreateAudit;
                    targetItem.AllowModifyAudit = importItem.AllowModifyAudit;
                    targetItem.AllowTimestamp   = importItem.AllowTimestamp;
                    targetItem.IsTenant         = importItem.IsTenant;
                    DatabaseImportDomain.PopulateFields(_model, importItem, targetItem);
                    this.Text += " [Entity: " + targetItem.Name + "]";
                }
                #endregion

                #region View
                else if (_modelElement is nHydrate.Dsl.View)
                {
                    var targetItem = _modelElement as nHydrate.Dsl.View;
                    var importItem = _importDomain.GetView(DatabaseConnectionControl1.ImportOptions.GetConnectionString(), (string)cboItem.SelectedItem, _auditFields);
                    targetItem.SQL = importItem.SQL;
                    DatabaseImportDomain.PopulateFields(_model, importItem, targetItem);
                    this.Text += " [View: " + targetItem.Name + "]";
                }
                #endregion

                transaction.Commit();
            }

            DatabaseConnectionControl1.PersistSettings();
        }
Exemplo n.º 5
0
        public ImportStaticDataForm()
        {
            InitializeComponent();

            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;
            DatabaseConnectionControl1.LoadSettings();
        }
Exemplo n.º 6
0
        public ImportStaticDataForm(nHydrate.Dsl.Entity entity, Microsoft.VisualStudio.Modeling.Store store, Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
            : this()
        {
            _entity = entity;
            _store  = store;

            lblWelcome.Text = "This wizard will walk you through the process of import static data from a database entity. The database entity schema must match the target function '" + entity.Name + "' in the modelRoot.";

            this.DatabaseConnectionControl1.FileName = Path.Combine((new FileInfo(docData.FileName)).DirectoryName, "importconnection.cache");
            DatabaseConnectionControl1.LoadSettings();
        }
Exemplo n.º 7
0
        private void cmdTestConnection_Click(object sender, EventArgs e)
        {
            DatabaseConnectionControl1.RefreshOptions();
            var connectString = DatabaseConnectionControl1.ImportOptions.GetConnectionString();
            var valid         = DatabaseHelper.TestConnectionString(connectString);

            if (valid)
            {
                MessageBox.Show("Connection Succeeded.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("The information does not describe a valid connection string.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 8
0
        private void wizard1_BeforeSwitchPages(object sender, nHydrate.Wizard.Wizard.BeforeSwitchPagesEventArgs e)
        {
            if (e.OldIndex == 0)
            {
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    DatabaseConnectionControl1.PersistSettings();
                    var connectionString = DatabaseConnectionControl1.ImportOptions.GetConnectionString();

                    if (!SqlSchemaToModel.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 nHydrateGeneratorProject();
                    SqlSchemaToModel.SetupNewProject(project, connectionString);
                    this.NewDatabase = (project.Model as ModelRoot).Database;
                    SqlSchemaToModel.GetProjectFromSqlSchema(project, connectionString, false, chkInheritance.Checked);

                    //Load the tree
                    this.Populate();

                    if (!this.AreChanges())
                    {
                        this.Cursor = Cursors.Default;
                        e.Cancel    = true;
                        MessageBox.Show("This model is up-to-date. There are no changes to refresh.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Exemplo n.º 9
0
        private void cmdTestConnection_Click(object sender, EventArgs e)
        {
            try
            {
                //SQL
                if (optDatabaseTypeSQL.Checked)
                {
                    DatabaseConnectionControl1.RefreshOptions();
                    var connectString  = DatabaseConnectionControl1.ImportOptions.GetConnectionString();
                    var importDomain   = new nHydrate.DataImport.SqlClient.ImportDomain();
                    var databaseHelper = importDomain.DatabaseDomain;

                    var valid = databaseHelper.TestConnectionString(connectString);
                    if (valid)
                    {
                        MessageBox.Show("Connection Succeeded.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("The information does not describe a valid connection string.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (optDatabaseTypePostgres.Checked) //Postgres
                {
                    if (DslPackage.Objects.Postgres.ImportDomain.TestConnection(txtConnectionStringPostgres.Text))
                    {
                        MessageBox.Show("Connection Succeeded.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("The information does not describe a valid connection string.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Unknown database type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 10
0
        public RefreshItemFromDatabase(
            nHydrateModel model,
            nHydrate.Dsl.IDatabaseEntity modelElement,
            Microsoft.VisualStudio.Modeling.Store store,
            Microsoft.VisualStudio.Modeling.Shell.ModelingDocData docData)
            : this()
        {
            if (modelElement == null)
            {
                throw new Exception("Model element canot be null.");
            }

            _model        = model;
            _store        = store;
            _modelElement = modelElement;
            _importDomain = new nHydrate.DataImport.SqlClient.ImportDomain();

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

            //Setup new model
            _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
            });

            wizard1.FinishEnabled = false;
        }
Exemplo n.º 11
0
        public ImportDatabaseForm()
        {
            InitializeComponent();

            tvwAdd.AfterCheck           += new TreeViewEventHandler(treeView1_AfterCheck);
            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;

            this.SelectedTables = new List <string>();
            this.SelectedViews  = new List <string>();

            DatabaseConnectionControl1.LoadSettings();
        }
Exemplo n.º 12
0
 private void cmdOK_Click(object sender, System.EventArgs e)
 {
     DatabaseConnectionControl1.PersistSettings();
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
Exemplo n.º 13
0
 public ConnectStringForm()
 {
     InitializeComponent();
     DatabaseConnectionControl1.LoadSettings();
 }
Exemplo n.º 14
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
                {
                    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.ModifiedDate
                    });
                    auditFields.Add(new SpecialField {
                        Name = _model.ConcurrencyCheckColumnName, Type = SpecialFieldTypeConstants.Timestamp
                    });
                    auditFields.Add(new SpecialField {
                        Name = _model.TenantColumnName, Type = SpecialFieldTypeConstants.Tenant
                    });

                    var pkey = ProgressHelper.ProgressingStarted("Importing...", true);
                    try
                    {
                        if (optDatabaseTypeSQL.Checked)
                        {
                            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;
                            }

                            LoadSqlServer(connectionString, auditFields);
                            ProgressHelper.ProgressingComplete(pkey);
                        }
                        else if (optDatabaseTypePostgres.Checked)
                        {
                            var connectionString = txtConnectionStringPostgres.Text;

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

                            var errorCount = LoadPostgres(connectionString, auditFields);
                            ProgressHelper.ProgressingComplete(pkey);
                            if (errorCount > 0)
                            {
                                MessageBox.Show("There were " + errorCount + " error on import.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Unknown database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    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();
            }
        }