Exemplo n.º 1
0
        private void cmdLegacy_Click(object sender, EventArgs e)
        {
            var F = new ImportLegacy();

            if (F.ShowDialog() == DialogResult.OK)
            {
                var uiKey = ProgressHelper.ProgressingStarted("Importing...", true, 60);
                try
                {
                    nHydrate.DslPackage.Objects.DatabaseImportDomain.ImportLegacyModel(_model, _store, _diagram, F.ModelFileName);
                }
                catch (Exception ex)
                {
                    throw;
                }
                finally
                {
                    ProgressHelper.ProgressingComplete(uiKey);
                }
                this.Close();
            }
        }
Exemplo n.º 2
0
        private void ModelUtilitiesForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }

            //HIDDEN - Turn off transform names
            if (e.KeyCode == Keys.Q && e.Control)
            {
                if (_model.TransformNames)
                {
                    if (MessageBox.Show("Rename all items to Pascal name?", "Rename", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        var uiKey = ProgressHelper.ProgressingStarted("Converting...", true, 60);
                        try
                        {
                            using (var transaction = _store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
                            {
                                _model.Entities.ForEach(x => x.Name = x.PascalName);
                                _model.Entities.ForEach(x => x.Fields.ForEach(y => y.Name = y.PascalName));

                                _model.Views.ForEach(x => x.Name = x.PascalName);
                                _model.Views.ForEach(x => x.Fields.ForEach(y => y.Name = y.PascalName));

                                _model.StoredProcedures.ForEach(x => x.Name = x.PascalName);
                                _model.StoredProcedures.ForEach(x => x.Fields.ForEach(y => y.Name     = y.PascalName));
                                _model.StoredProcedures.ForEach(x => x.Parameters.ForEach(y => y.Name = y.PascalName));

                                _model.Functions.ForEach(x => x.Name = x.PascalName);
                                _model.Functions.ForEach(x => x.Fields.ForEach(y => y.Name     = y.PascalName));
                                _model.Functions.ForEach(x => x.Parameters.ForEach(y => y.Name = y.PascalName));

                                _model.TransformNames         = false;
                                _model.CreatedByColumnName    = nHydrate.Generator.Common.Util.StringHelper.DatabaseNameToPascalCase(_model.CreatedByColumnName);
                                _model.CreatedDateColumnName  = nHydrate.Generator.Common.Util.StringHelper.DatabaseNameToPascalCase(_model.CreatedDateColumnName);
                                _model.ModifiedByColumnName   = nHydrate.Generator.Common.Util.StringHelper.DatabaseNameToPascalCase(_model.ModifiedByColumnName);
                                _model.ModifiedDateColumnName = nHydrate.Generator.Common.Util.StringHelper.DatabaseNameToPascalCase(_model.ModifiedDateColumnName);
                                _model.TimestampColumnName    = nHydrate.Generator.Common.Util.StringHelper.DatabaseNameToPascalCase(_model.TimestampColumnName);
                                transaction.Commit();
                            }
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            ProgressHelper.ProgressingComplete(uiKey);
                            throw;
                        }
                        finally
                        {
                            ProgressHelper.ProgressingComplete(uiKey);
                        }
                    }
                }
            }

            //HIDDEN
            else if (e.KeyCode == Keys.W && e.Control)
            {
                var F = new UserDefinedScriptOrderForm(_model, _store);
                F.ShowDialog();
            }
        }
Exemplo n.º 3
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            var uiKey = ProgressHelper.ProgressingStarted("Saving Modules...");

            try
            {
                using (var transaction = _model.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString()))
                {
                    var module = _model.Modules.FirstOrDefault(x => x.Name == (string)cboModule.SelectedItem);
                    foreach (var item in _nodeCache)
                    {
                        if (item.Value.Checked)
                        {
                            if (item.Key.Modules.Count(x => x == module) == 0)
                            {
                                item.Key.AddModule(module);

                                //Add PK if entity
                                if (item.Key is Entity)
                                {
                                    var entity = item.Key as Entity;
                                    var pk     = entity.Indexes.FirstOrDefault(x => x.IndexType == IndexTypeConstants.PrimaryKey);
                                    if (pk != null && !_model.IndexModules.Any(x => x.IndexID == pk.Id && x.ModuleId == module.Id))
                                    {
                                        _model.IndexModules.Add(new IndexModule(_model.Partition)
                                        {
                                            IndexID = pk.Id, ModuleId = module.Id
                                        });
                                    }
                                }
                            }
                        }
                        else
                        {
                            item.Key.RemoveModule(module);

                            //Remove PK if entity
                            if (item.Key is Entity)
                            {
                                var entity = item.Key as Entity;
                                var pk     = entity.Indexes.FirstOrDefault(x => x.IndexType == IndexTypeConstants.PrimaryKey);
                                if (pk != null)
                                {
                                    _model.IndexModules.Remove(x => (x.IndexID == pk.Id) && (x.ModuleId == module.Id));
                                }
                            }
                        }
                    }

                    //Now process the enforce bits
                    var allRelations = _nodeCache.Keys.Where(x => x is EntityHasEntities).ToList();
                    foreach (var key in allRelations)
                    {
                        if (_nodeCache[key].Checked)
                        {
                            var relation       = _nodeCache[key].Tag as EntityHasEntities;
                            var relationModule = _model.RelationModules.FirstOrDefault(x => x.RelationID == relation.Id && x.ModuleId == module.Id);
                            if (relationModule == null)
                            {
                                _model.RelationModules.Add(new RelationModule(_model.Partition)
                                {
                                    RelationID = relation.Id,
                                    ModuleId   = module.Id,
                                    Included   = true,
                                    IsEnforced = _relationEnforcement[relation]
                                });
                            }
                            else
                            {
                                relationModule.IsEnforced = _relationEnforcement[relation];
                            }
                        }
                    }

                    //Process Indexes
                    var allIndexes = _nodeCache.Keys.Where(x => x is Index).ToList();
                    foreach (var key in allIndexes)
                    {
                        if (_nodeCache[key].Checked)
                        {
                            var index       = _nodeCache[key].Tag as Index;
                            var indexModule = _model.IndexModules.FirstOrDefault(x => x.IndexID == index.Id && x.ModuleId == module.Id);
                            if (indexModule == null)
                            {
                                _model.IndexModules.Add(new IndexModule(_model.Partition)
                                {
                                    IndexID  = index.Id,
                                    ModuleId = module.Id,
                                });
                            }
                        }
                    }

                    transaction.Commit();
                }

                cmdSave.Enabled   = false;
                cmdCancel.Enabled = false;
                cboModule.Enabled = true;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                ProgressHelper.ProgressingComplete(uiKey);
            }
        }
Exemplo n.º 4
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();
            }
        }