void Generate(Table tb, bool isToFile = false) { //生成domain.cs string domainCs = CodeMaker.MakeDomainCs(tb, mySetting); //生成domain.designer.cs string domainDesignerCs = CodeMaker.MakeDomainDesignerCs(tb, mySetting); //生成IReposity string ireposityCs = CodeMaker.MakeIReposityCs(tb, mySetting); //生成Reposity.cs string reposityCs = CodeMaker.MakeReposityCs(tb, mySetting); //生成Reposity.designer.cs string reposityDesignerCs = CodeMaker.MakeReposityDesignerCs(tb, mySetting); if (!isToFile) { domainCodeFastColoredTextBox.Text = domainCs; fastColoredTextBox1.Text = domainDesignerCs; if (mySetting.IsAggregateRoot) { fastColoredTextBox2.Text = ireposityCs; fastColoredTextBox3.Text = reposityCs; fastColoredTextBox4.Text = reposityDesignerCs; } else { //不是聚合根不必要生成仓储类 fastColoredTextBox2.Text = ""; fastColoredTextBox3.Text = ""; fastColoredTextBox4.Text = ""; } } else { //先修改项目文件 UpdateCsprojFile(mySetting.DominFolderPath, Path.Combine(mySetting.DomainDir, tb.ClassName + ".cs"), Path.Combine(mySetting.DomainDir, tb.ClassName + ".designer.cs")); WriteToFile(Path.Combine(Path.GetDirectoryName(mySetting.DominFolderPath), mySetting.DomainDir), tb.ClassName + ".cs", domainCs, mySetting.IsReWroteCsFile); WriteToFile(Path.Combine(Path.GetDirectoryName(mySetting.DominFolderPath), mySetting.DomainDir), tb.ClassName + ".designer.cs", domainDesignerCs, true); if (mySetting.IsAggregateRoot) { //聚合根才要生成仓储类 //修改项目文件 UpdateCsprojFile(mySetting.IReposityFolderPath, Path.Combine(mySetting.IReposityDir, "I" + tb.ClassName + "Repository.cs"), null); UpdateCsprojFile(mySetting.ReposityFolderPath, Path.Combine(mySetting.ReposityDir, tb.ClassName + "Repository.cs"), Path.Combine(mySetting.ReposityDir, tb.ClassName + "Repository.designer.cs")); WriteToFile(Path.Combine(Path.GetDirectoryName(mySetting.IReposityFolderPath), mySetting.IReposityDir), "I" + tb.ClassName + "Repository.cs", ireposityCs, mySetting.IsReWroteCsFile); WriteToFile(Path.Combine(Path.GetDirectoryName(mySetting.ReposityFolderPath), mySetting.ReposityDir), tb.ClassName + "Repository.cs", reposityCs, mySetting.IsReWroteCsFile); WriteToFile(Path.Combine(Path.GetDirectoryName(mySetting.ReposityFolderPath), mySetting.ReposityDir), tb.ClassName + "Repository.designer.cs", reposityDesignerCs, true); } } }
private void ConnectionButtonClick(object sender, EventArgs e) { // Belt and braces if (applicationSettings == null) { LoadApplicationSettings(); } var connectionDialog = new ConnectionDialog(); // Edit current connection if (_currentConnection != null) { connectionDialog.Connection = _currentConnection; } var result = connectionDialog.ShowDialog(); switch (result) { case DialogResult.OK: // Add or Update Connection _currentConnection = connectionDialog.Connection; var connectionToUpdate = applicationSettings.Connections.FirstOrDefault(connection => connection.Id == _currentConnection.Id); if (connectionToUpdate == null) { // Add new connection applicationSettings.Connections.Add(_currentConnection); } break; case DialogResult.Abort: // Delete Connection applicationSettings.Connections.Remove(_currentConnection); _currentConnection = null; break; } // Refresh data connections drop down connectionNameComboBox.DataSource = null; connectionNameComboBox.DataSource = applicationSettings.Connections; connectionNameComboBox.DisplayMember = "Name"; connectionNameComboBox.SelectedItem = _currentConnection; fastColoredTextBox5.Text = CodeMaker.MakeDbConfig(applicationSettings.Connections, checkBox4.Checked); }
private void button2_Click(object sender, EventArgs e) { var diagResult = folderBrowserDialog.ShowDialog(); if (diagResult == DialogResult.OK) { try { string folder = folderBrowserDialog.SelectedPath; var content = CodeMaker.MakeDbConfig(applicationSettings.Connections, checkBox4.Checked); WriteToFile(folder, "db.config", content, true); toolStripStatusLabel.Text = @"Generated db.config files successfully."; } catch (Exception ex) { toolStripStatusLabel.Text = @"Generated db.config files failed.:" + ex.Message; } } }
private void LoadApplicationSettings() { applicationSettings = ApplicationSettings.Load(); if (applicationSettings != null) { // Display all previous connections connectionNameComboBox.DataSource = applicationSettings.Connections; connectionNameComboBox.DisplayMember = "Name"; fastColoredTextBox5.Text = CodeMaker.MakeDbConfig(applicationSettings.Connections, checkBox4.Checked); // Set the last used connection var lastUsedConnection = applicationSettings.Connections.FirstOrDefault(connection => connection.Id == applicationSettings.LastUsedConnection); _currentConnection = lastUsedConnection ?? applicationSettings.Connections.FirstOrDefault(); connectionNameComboBox.SelectedItem = _currentConnection; DomainNmespaceTextBox.Text = applicationSettings.NameSpace; IReposityNamespaceTextBox.Text = applicationSettings.NameSpaceMap; ReposityNamespaceTextBox.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; DomainFolderTextBox.Text = applicationSettings.FolderPath; IReposityFolderTextBox.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; } LoadMySetting(); }