private void button2_Click(object sender, EventArgs e) { List<string> res = new List<string>(); foreach (DataGridViewRow row in dataGridView1.Rows) if (bool.Parse(row.Cells[0].Value.ToString())) res.Add(row.Cells[1].Value as string); Dictionary<string, GFieldInfo[]> gfiss = new Dictionary<string, GFieldInfo[]>(); foreach(var t in Wizard.Schema.AllTables) if (res.Contains(t.Name)) { var Fields = new List<GFieldInfo>(); foreach (var c in t.Columns.Values) { var c_i = new GFieldInfo(); c_i.Name = c.Name; c_i.Type = c.Type.ToString(); c_i._db_type = c.DbType; Fields.Add(c_i); } gfiss.Add(t.Name, Fields.ToArray()); } List<GeneralProperty> ths = new List<GeneralProperty>(); foreach (KeyValuePair<string, GFieldInfo[]> gfis in gfiss) { GeneralProperty gp = new GeneralProperty(); gp.Fields = new List<GFieldInfo>(gfis.Value); gp.OwnerFields = new List<OwnerFieldInfo>(); gp.TableName = gfis.Key; ths.Add(gp); } Wizard.Tables = ths.ToArray(); Wizard.NextStep(); }
private System.CodeDom.CodeNamespace _getNamespace(GeneralProperty gp, string Namespace) { System.CodeDom.CodeNamespace cns = new System.CodeDom.CodeNamespace(Namespace); cns.Imports.Add(new CodeNamespaceImport("System")); cns.Imports.Add(new CodeNamespaceImport("Burst")); cns.Imports.Add(new CodeNamespaceImport("Burst.Data")); cns.Imports.Add(new CodeNamespaceImport("Burst.Data.Entity")); if (gp != null && gp.IsWebUserModel) cns.Imports.Add(new CodeNamespaceImport("Burst.Web")); return cns; }
private CodeTypeDeclaration _getType(GeneralProperty gp) { CodeTypeDeclaration model = new CodeTypeDeclaration(gp.ClassName); if (gp.IsWebUserModel) { model.BaseTypes.Add( new CodeTypeReference("UserBase", new CodeTypeReference[] { new CodeTypeReference(gp.ClassName) })); } else { model.BaseTypes.Add( new CodeTypeReference("DataEntity", new CodeTypeReference[] { new CodeTypeReference(gp.ClassName) })); } model.TypeAttributes = TypeAttributes.Public; model.IsPartial = true; return model; }
public string GenerateFieldsFile(GeneralProperty GeneralProperty, string Namespace, string Language) { CodeCompileUnit ccu = new CodeCompileUnit(); System.CodeDom.CodeNamespace cns = _getNamespace(GeneralProperty, Namespace); CodeTypeDeclaration model = _getType(GeneralProperty); model.CustomAttributes.Add( new CodeAttributeDeclaration("DataEntity", new CodeAttributeArgument(new CodePrimitiveExpression(GeneralProperty.TableName)), new CodeAttributeArgument(new CodePrimitiveExpression(GeneralProperty.UseCache)) ) ); CodeMemberMethod setvalue = new CodeMemberMethod(); setvalue.Attributes = MemberAttributes.Override | MemberAttributes.Family; setvalue.Name = "SetValue"; setvalue.Parameters.Add( new CodeParameterDeclarationExpression(typeof(string), "Key") ); setvalue.Parameters.Add( new CodeParameterDeclarationExpression(typeof(object), "Value") ); int _startIndex = 0; if (GeneralProperty.IsWebUserModel) _startIndex = 4; for (int i = _startIndex; i < GeneralProperty.Fields.Count; i++) { var fieldinfo = GeneralProperty.Fields[i]; setvalue.Statements.Add(new CodeConditionStatement( new CodeBinaryOperatorExpression( new CodeArgumentReferenceExpression("Key"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(fieldinfo.Name) ), new CodeAssignStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), "__" + fieldinfo.Name ), new CodeCastExpression( _addField(fieldinfo, model), new CodeArgumentReferenceExpression("Value") ) ) )); } setvalue.Statements.Add( new CodeExpressionStatement( new CodeMethodInvokeExpression( new CodeBaseReferenceExpression(), "SetValue", new CodeExpression[] { new CodeArgumentReferenceExpression("Key"), new CodeArgumentReferenceExpression("Value") } ) ) ); model.Members.Add(setvalue); cns.Types.Add(model); ccu.Namespaces.Add(cns); Entities.Add(GeneralProperty.ClassName); return _getString(ccu, Language); }
public string GenerateBaseFile(GeneralProperty GeneralProperty, string Namespace, string Language) { CodeCompileUnit ccu = new CodeCompileUnit(); System.CodeDom.CodeNamespace cns = _getNamespace(GeneralProperty, Namespace); CodeTypeDeclaration model = _getType(GeneralProperty); cns.Types.Add(model); ccu.Namespaces.Add(cns); return _getString(ccu, Language); }
public frmFields(GeneralProperty GeneralProperty) { InitializeComponent(); pgMain.SelectedObject = GeneralProperty; }
public static void Generate( IGenerator generator, DTE DTE, GeneralProperty[] GeneralProperties, bool OverwriteAll, bool ToPascalName, bool GenerateInitializer, NameValueList InitializeParameters, string Namespace ) { Project _project = Utils.GetProject(DTE); ProjectItem pi = Utils.GetSelectedDirectory(DTE); ProjectItems _currentDirectory = null; string _path = null; string _language = null; string _fileExtension = null; if (pi != null) { _currentDirectory = pi.ProjectItems; _path = pi.Properties.Item("FullPath").Value.ToString(); } else { _currentDirectory = _project.ProjectItems; _path = _project.Properties.Item("FullPath").Value.ToString(); } if (_project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageCSharp) { _language = "CSharp"; _fileExtension = ".cs"; } else if (_project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVB) { _language = "VisualBasic"; _fileExtension = ".vb"; } //Generate foreach (GeneralProperty gp in GeneralProperties) { if (string.IsNullOrWhiteSpace(gp.ClassName)) { if (ToPascalName) gp.ClassName = gp.TableName.ToPascalName(); else gp.ClassName = gp.TableName; } foreach (GFieldInfo fieldinfo in gp.Fields) if (string.IsNullOrWhiteSpace(fieldinfo.DisplayName)) { if (ToPascalName) fieldinfo.DisplayName = fieldinfo.Name.ToPascalName(); else fieldinfo.DisplayName = fieldinfo.Name; } /* foreach (OwnerFieldInfo ownerfieldinfo in gp.OwnerFields) if (string.IsNullOrWhiteSpace(ownerfieldinfo.DisplayName)) { if (ToPascalName) ownerfieldinfo.DisplayName = ownerfieldinfo.Name.ToPascalName(); else ownerfieldinfo.DisplayName = ownerfieldinfo.Name; } */ ProjectItem _baseItem = null; string basefile = Path.Combine(_path, gp.ClassName + _fileExtension); if (OverwriteAll) File.WriteAllText(basefile, generator.GenerateBaseFile(gp, Namespace, _language)); try { _baseItem = _currentDirectory.Item(Path.GetFileName(basefile)); } catch { if (!OverwriteAll) File.WriteAllText(basefile, generator.GenerateBaseFile(gp, Namespace, _language)); _baseItem = _currentDirectory.AddFromFile(basefile); } string fieldsfile = Path.Combine(_path, gp.ClassName + ".Fields" + _fileExtension); File.WriteAllText(fieldsfile, generator.GenerateFieldsFile(gp, Namespace, _language)); try { _baseItem.ProjectItems.Item(Path.GetFileName(fieldsfile)); } catch { _baseItem.ProjectItems.AddFromFile(fieldsfile); } /* string ownerfieldsfile = Path.Combine(_path, gp.ClassName + ".OwnerFields" + _fileExtension); if (OverwriteAll && File.Exists(ownerfieldsfile) || gp.OwnerFields.Count > 0) { File.WriteAllText(ownerfieldsfile, generator.GenerateOwnerFieldsFile(gp, Namespace, _language)); try { _baseItem.ProjectItems.Item(Path.GetFileName(ownerfieldsfile)); } catch { _baseItem.ProjectItems.AddFromFile(ownerfieldsfile); } } */ } if (GenerateInitializer) { var init_file = Path.Combine(_path, "DbInitializer" + _fileExtension); File.WriteAllText( init_file, generator.GenerateInitializeFile(InitializeParameters, Namespace, _language) ); try { _currentDirectory.Item(Path.GetFileName(init_file)); } catch { _currentDirectory.AddFromFile(init_file); } } }