private void ToggleColumnsBasedOnAppSettings(ApplicationSettings appSettings) { var lengthColumn = dbTableDetailsGridView.Columns["DataLength"]; if (lengthColumn != null) lengthColumn.Visible = appSettings.IncludeLengthAndScale; var precisionColumn = dbTableDetailsGridView.Columns["DataPrecision"]; if (precisionColumn != null) precisionColumn.Visible = appSettings.IncludeLengthAndScale; var scaleColumn = dbTableDetailsGridView.Columns["DataScale"]; if (scaleColumn != null) scaleColumn.Visible = appSettings.IncludeLengthAndScale; var cSharpTypeColumn = dbTableDetailsGridView.Columns["cSharpType"]; if (cSharpTypeColumn != null) cSharpTypeColumn.Visible = !appSettings.IsByCode; /*var fkTableNameColumn = dbTableDetailsGridView.Columns["ForeignKeyTableName"]; var fkColNameColumn = dbTableDetailsGridView.Columns["ForeignKeyColumnName"]; if (fkColNameColumn != null && fkTableNameColumn != null) { if (_currentTable.ForeignKeys.Count != 0) { // Disable foreign key columns fkTableNameColumn.ReadOnly = false; fkColNameColumn.ReadOnly = false; } else { // Enable foreign key columns fkTableNameColumn.ReadOnly = true; fkColNameColumn.ReadOnly = true; } }*/ }
private void LoadApplicationSettings() { applicationSettings = ApplicationSettings.Load(); if (applicationSettings != null) { // Display all previous connections connectionNameComboBox.DataSource = applicationSettings.Connections; connectionNameComboBox.DisplayMember = "Name"; // Set the last used connection var lastUsedConnection = applicationSettings.Connections.FirstOrDefault(connection => connection.Id == applicationSettings.LastUsedConnection); _currentConnection = lastUsedConnection ?? applicationSettings.Connections.FirstOrDefault(); connectionNameComboBox.SelectedItem = _currentConnection; nameSpaceTextBox.Text = applicationSettings.NameSpace; namespaceMapTextBox.Text = applicationSettings.NameSpaceMap; assemblyNameTextBox.Text = applicationSettings.AssemblyName; cSharpRadioButton.Checked = applicationSettings.Language == Language.CSharp; vbRadioButton.Checked = applicationSettings.Language == Language.VB; noValidationRadioButton.Checked = applicationSettings.ValidationStyle == ValidationStyle.None; nhibernateValidationRadioButton.Checked = applicationSettings.ValidationStyle == ValidationStyle.Nhibernate; dataAnnotationsRadioButton.Checked = applicationSettings.ValidationStyle == ValidationStyle.Microsoft; autoPropertyRadioBtn.Checked = applicationSettings.IsAutoProperty; folderTextBox.Text = applicationSettings.FolderPath; domainFolderTextBox.Text = applicationSettings.DomainFolderPath; textBoxInheritence.Text = applicationSettings.InheritenceAndInterfaces; comboBoxForeignCollection.Text = applicationSettings.ForeignEntityCollectionType; textBoxClassNamePrefix.Text = applicationSettings.ClassNamePrefix; EnableInflectionsCheckBox.Checked = applicationSettings.EnableInflections; wcfDataContractCheckBox.Checked = applicationSettings.GenerateWcfContracts; partialClassesCheckBox.Checked = applicationSettings.GeneratePartialClasses; useLazyLoadingCheckBox.Checked = applicationSettings.UseLazy; includeLengthAndScaleCheckBox.Checked = applicationSettings.IncludeLengthAndScale; includeForeignKeysCheckBox.Checked = applicationSettings.IncludeForeignKeys; nameAsForeignTableCheckBox.Checked = applicationSettings.NameFkAsForeignTable; includeHasManyCheckBox.Checked = applicationSettings.IncludeHasMany; fluentMappingOption.Checked = applicationSettings.IsFluent; entityFrameworkRadionBtn.Checked = applicationSettings.IsEntityFramework; castleMappingOption.Checked = applicationSettings.IsCastle; byCodeMappingOption.Checked = applicationSettings.IsByCode; if (applicationSettings.FieldPrefixRemovalList == null) applicationSettings.FieldPrefixRemovalList = new List<string>(); fieldPrefixListBox.Items.AddRange(applicationSettings.FieldPrefixRemovalList.ToArray()); removeFieldPrefixButton.Enabled = false; prefixRadioButton.Checked = !string.IsNullOrEmpty(applicationSettings.Prefix); prefixTextBox.Text = applicationSettings.Prefix; camelCasedRadioButton.Checked = (applicationSettings.FieldNamingConvention == FieldNamingConvention.CamelCase); pascalCasedRadioButton.Checked = (applicationSettings.FieldNamingConvention == FieldNamingConvention.PascalCase); sameAsDBRadioButton.Checked = (applicationSettings.FieldNamingConvention == FieldNamingConvention.SameAsDatabase); sameAsDBRadioButton.Checked = (!prefixRadioButton.Checked && !pascalCasedRadioButton.Checked && !camelCasedRadioButton.Checked); generateInFoldersCheckBox.Checked = applicationSettings.GenerateInFolders; SetCodeControlFormatting(applicationSettings); } else { // Default application settings autoPropertyRadioBtn.Checked = true; pascalCasedRadioButton.Checked = true; cSharpRadioButton.Checked = true; byCodeMappingOption.Checked = true; includeForeignKeysCheckBox.Checked = true; nameAsForeignTableCheckBox.Checked = true; includeHasManyCheckBox.Checked = false; useLazyLoadingCheckBox.Checked = true; comboBoxForeignCollection.Text = "IList"; CaptureApplicationSettings(); } if (!prefixRadioButton.Checked) { prefixLabel.Visible = prefixTextBox.Visible = false; } }
private void SetCodeControlFormatting(ApplicationSettings appSettings) { // Domain Code Formatting if (appSettings.Language == Language.CSharp) { domainCodeFastColoredTextBox.Language = FastColoredTextBoxNS.Language.CSharp; } else if (appSettings.Language == Language.VB) { domainCodeFastColoredTextBox.Language = FastColoredTextBoxNS.Language.VB; } // Map Code Formatting if (appSettings.Language == Language.CSharp & appSettings.IsByCode || appSettings.IsFluent || appSettings.IsNhFluent || appSettings.IsCastle || appSettings.IsEntityFramework) { mapCodeFastColoredTextBox.Language = FastColoredTextBoxNS.Language.CSharp; } else if (appSettings.Language == Language.VB & appSettings.IsByCode || appSettings.IsFluent || appSettings.IsNhFluent || appSettings.IsCastle || appSettings.IsEntityFramework) { mapCodeFastColoredTextBox.Language = FastColoredTextBoxNS.Language.VB; } else { mapCodeFastColoredTextBox.Language = FastColoredTextBoxNS.Language.HTML; } }
private void Generate(Table table, bool generateAll, ApplicationSettings appSettings) { var applicationPreferences = GetApplicationPreferences(table, generateAll, appSettings); new ApplicationController(applicationPreferences, table).Generate(); }
private ApplicationPreferences GetApplicationPreferences(Table tableName, bool all, ApplicationSettings appSettings) { string sequence = string.Empty; object sequenceName = null; if (sequencesComboBox.InvokeRequired) { sequencesComboBox.Invoke(new MethodInvoker(delegate { sequenceName = sequencesComboBox.SelectedItem; })); } else { sequenceName = sequencesComboBox.SelectedItem; } if (sequenceName != null && !all) { sequence = sequenceName.ToString(); } var folderPath = AddSlashToFolderPath(folderTextBox.Text); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var domainFolderPath = AddSlashToFolderPath(domainFolderTextBox.Text); if (appSettings.GenerateInFolders) { Directory.CreateDirectory(folderPath + "Contract"); Directory.CreateDirectory(folderPath + "Domain"); Directory.CreateDirectory(folderPath + "Mapping"); domainFolderPath = folderPath; } else { // Domain folder is specified by user if (!Directory.Exists(domainFolderPath)) { Directory.CreateDirectory(domainFolderPath); } } var applicationPreferences = new ApplicationPreferences { ServerType = _currentConnection.Type, FolderPath = folderPath, DomainFolderPath = domainFolderPath, TableName = tableName.Name, NameSpaceMap = namespaceMapTextBox.Text, NameSpace = nameSpaceTextBox.Text, AssemblyName = assemblyNameTextBox.Text, Sequence = sequence, Language = LanguageSelected, FieldNamingConvention = GetFieldNamingConvention(), FieldGenerationConvention = GetFieldGenerationConvention(), Prefix = prefixTextBox.Text, IsFluent = IsFluent, IsEntityFramework = IsEntityFramework, IsCastle = IsCastle, GeneratePartialClasses = appSettings.GeneratePartialClasses, GenerateWcfDataContract = appSettings.GenerateWcfContracts, ConnectionString = _currentConnection.ConnectionString, ForeignEntityCollectionType = appSettings.ForeignEntityCollectionType, InheritenceAndInterfaces = appSettings.InheritenceAndInterfaces, GenerateInFolders = appSettings.GenerateInFolders, ClassNamePrefix = appSettings.ClassNamePrefix, EnableInflections = appSettings.EnableInflections, IsByCode = appSettings.IsByCode, UseLazy = appSettings.UseLazy, FieldPrefixRemovalList = appSettings.FieldPrefixRemovalList, IncludeForeignKeys = appSettings.IncludeForeignKeys, NameFkAsForeignTable = appSettings.NameFkAsForeignTable, IncludeHasMany = appSettings.IncludeHasMany, IncludeLengthAndScale = appSettings.IncludeLengthAndScale, ValidatorStyle = appSettings.ValidationStyle }; return applicationPreferences; }
private void CaptureApplicationSettings() { if (applicationSettings == null) { applicationSettings = new ApplicationSettings(); } applicationSettings.NameSpace = nameSpaceTextBox.Text; applicationSettings.NameSpaceMap = namespaceMapTextBox.Text; applicationSettings.AssemblyName = assemblyNameTextBox.Text; applicationSettings.Language = cSharpRadioButton.Checked ? Language.CSharp : Language.VB; var validationStyle = ValidationStyle.None; if (dataAnnotationsRadioButton.Checked) validationStyle = ValidationStyle.Microsoft; if (nhibernateValidationRadioButton.Checked) validationStyle = ValidationStyle.Nhibernate; applicationSettings.ValidationStyle = validationStyle; applicationSettings.IsFluent = fluentMappingOption.Checked; applicationSettings.IsEntityFramework = entityFrameworkRadionBtn.Checked; applicationSettings.IsAutoProperty = autoPropertyRadioBtn.Checked; applicationSettings.FolderPath = folderTextBox.Text; applicationSettings.DomainFolderPath = domainFolderTextBox.Text; applicationSettings.InheritenceAndInterfaces = textBoxInheritence.Text; applicationSettings.ForeignEntityCollectionType = comboBoxForeignCollection.Text; applicationSettings.FieldPrefixRemovalList = applicationSettings.FieldPrefixRemovalList; applicationSettings.FieldNamingConvention = GetFieldNamingConvention(); applicationSettings.Prefix = prefixTextBox.Text; applicationSettings.IsCastle = IsCastle; applicationSettings.ClassNamePrefix = textBoxClassNamePrefix.Text; applicationSettings.EnableInflections = EnableInflectionsCheckBox.Checked; applicationSettings.GeneratePartialClasses = partialClassesCheckBox.Checked; applicationSettings.GenerateWcfContracts = wcfDataContractCheckBox.Checked; applicationSettings.GenerateInFolders = generateInFoldersCheckBox.Checked; applicationSettings.IsByCode = IsByCode; applicationSettings.UseLazy = useLazyLoadingCheckBox.Checked; applicationSettings.IncludeForeignKeys = includeForeignKeysCheckBox.Checked; applicationSettings.NameFkAsForeignTable = nameAsForeignTableCheckBox.Checked; applicationSettings.IncludeHasMany = includeHasManyCheckBox.Checked; applicationSettings.IncludeLengthAndScale = includeLengthAndScaleCheckBox.Checked; applicationSettings.LastUsedConnection = _currentConnection == null ? (Guid?) null : _currentConnection.Id; }
private void newProjectMenu_Click(object sender, EventArgs e) { var applicationSettings = new ApplicationSettings(connStrTextBox.Text, (ServerType)serverTypeComboBox.SelectedItem, nameSpaceTextBox.Text, assemblyNameTextBox.Text); _applicationSettings = applicationSettings; projectNameTextBox.Text = " New NMG Project"; _applicationSettings.ProjectName = projectNameTextBox.Text; _isDirty = true; this.mainTabControl.Enabled = true; }
private void loadProjectMenu_Click(object sender, EventArgs e) { OpenFileDialog saveProjectDialog = new OpenFileDialog(); saveProjectDialog.ShowDialog(); string projectFile = saveProjectDialog.FileName; _applicationSettings = ApplicationSettings.Load(projectFile); if(_applicationSettings == null) { MessageBox.Show("Cannot open project !"); return; } LoadApplicationSettings(); _currentProjectPath = GetSafeProjectPath(saveProjectDialog.FileName); // just opened project so it's not dirty _isDirty = false; UpdateFormTextStatus(); this.mainTabControl.Enabled = true; }
private ApplicationPreferences GetApplicationPreferences(Table tableName, bool all, ApplicationSettings appSettings) { string sequence = string.Empty; object sequenceName = null; if (sequencesComboBox.InvokeRequired) { sequencesComboBox.Invoke(new MethodInvoker(delegate { sequenceName = sequencesComboBox.SelectedItem; })); } else { sequenceName = sequencesComboBox.SelectedItem; } if (sequenceName != null && !all) { sequence = sequenceName.ToString(); } var folderPath = AddSlashToFolderPath(folderTextBox.Text); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } if (appSettings.GenerateInFolders) { Directory.CreateDirectory(folderPath + "Contract"); Directory.CreateDirectory(folderPath + "Domain"); Directory.CreateDirectory(folderPath + "Mapping"); } object serverType = null; if (serverTypeComboBox.InvokeRequired) { serverTypeComboBox.Invoke(new MethodInvoker(delegate { serverType = serverTypeComboBox.SelectedItem; })); } else { serverType = serverTypeComboBox.SelectedItem; } var applicationPreferences = new ApplicationPreferences { ServerType = (ServerType)serverType, FolderPath = folderPath, TableName = tableName.Name, NameSpace = nameSpaceTextBox.Text, AssemblyName = assemblyNameTextBox.Text, Sequence = sequence, Language = LanguageSelected, FieldNamingConvention = GetFieldNamingConvention(), FieldGenerationConvention = GetFieldGenerationConvention(), Prefix = prefixTextBox.Text, IsFluent = IsFluent, IsNhFluent = IsNhFluent, IsCastle = IsCastle, GeneratePartialClasses = appSettings.GeneratePartialClasses, GenerateWcfDataContract = appSettings.GenerateWcfContracts, ConnectionString = appSettings.ConnectionString, ForeignEntityCollectionType = appSettings.ForeignEntityCollectionType, InheritenceAndInterfaces = appSettings.InheritenceAndInterfaces, GenerateInFolders = appSettings.GenerateInFolders, ClassNamePrefix = appSettings.ClassNamePrefix, IsByCode = appSettings.IsByCode, UseLazy = useLazyLoadingCheckBox.Checked, IncludeForeignKeys = includeForeignKeysCheckBox.Checked, NamespaceCliente = tbNamespaceCliente.Text, AssemblyCliente = tbAssemblyCliente.Text }; return(applicationPreferences); }
private void App_Closing(object sender, CancelEventArgs e) { applicationSettings = CaptureApplicationSettings(); applicationSettings.Save(); }