/// <summary> /// 生成属性 /// </summary> /// <returns></returns> private string GenProperty() { StringBuilder sbProperty = new StringBuilder(); if (Table.Params == null) { return(sbProperty.ToString()); } foreach (EntityParam epf in Table.Params) { //if (!epf.IsGenerate) //{ // continue; //} sbProperty.AppendLine(" private BQLEntityParamHandle " + epf.FieldName + " = null;"); sbProperty.AppendLine(" /// <summary>"); sbProperty.AppendLine(DBEntityInfo.FormatSummary(epf.Description)); sbProperty.AppendLine(" /// </summary>"); sbProperty.AppendLine(" public BQLEntityParamHandle " + epf.PropertyName + ""); sbProperty.AppendLine(" {"); sbProperty.AppendLine(" get"); sbProperty.AppendLine(" {"); sbProperty.AppendLine(" return " + epf.FieldName + ";"); sbProperty.AppendLine(" }"); sbProperty.AppendLine(" }"); } return(sbProperty.ToString()); }
void gvTables_RowPrePaint(object sender, System.Windows.Forms.DataGridViewRowPrePaintEventArgs e) { int row = e.RowIndex; if (row < 0) { return; } DataGridViewRow dr = gvTables.Rows[row]; string exists = "未生成"; DBTableInfo info = dr.DataBoundItem as DBTableInfo; if (info != null) { string fileName = DBEntityInfo.GetEntityRealFileName(info, _dbInfo, DesignerInfo); try { if (File.Exists(fileName)) { exists = "已生成"; dr.DefaultCellStyle.ForeColor = Color.Red; } } catch { } } dr.Cells["ColExists"].Value = exists; }
/// <summary> /// 生成映射属性 /// </summary> /// <returns></returns> private string GenRelation() { StringBuilder sbRelation = new StringBuilder(); if (Table.RelationItems == null) { return(sbRelation.ToString()); } foreach (TableRelationAttribute er in Table.RelationItems) { //if (!er.IsGenerate) //{ // continue; //} //string targetType = er.FInfo.MemberTypeShortName; //if (er.IsParent) //{ string targetType = er.FieldTypeName; sbRelation.AppendLine(" /// <summary>"); sbRelation.AppendLine(DBEntityInfo.FormatSummary(er.Description)); sbRelation.AppendLine(" /// </summary>"); string type = null; if (!er.IsParent) { targetType = er.FieldTypeName; int indexStart = targetType.IndexOf("<"); int indexEnd = targetType.LastIndexOf(">"); if (indexStart > 0 && indexEnd > 0) { targetType = targetType.Substring(indexStart + 1, indexEnd - indexStart - 1); } } type = FormatClassName(targetType); sbRelation.AppendLine(" public " + type + " " + er.PropertyName + ""); sbRelation.AppendLine(" {"); sbRelation.AppendLine(" get"); sbRelation.AppendLine(" {"); sbRelation.AppendLine(" return new " + FormatClassName(targetType) + "(this,\"" + er.PropertyName + "\");"); //else //{ // sbRelation.Append(" Type objType = typeof(" + type + ");"); // sbRelation.Append(" return (" + type + ")Activator.CreateInstance(objType, this, \"" + er.PropertyName + "\");"); //} sbRelation.AppendLine(" }"); sbRelation.AppendLine(" }"); //} } return(sbRelation.ToString()); }
private void btnSubmit_Click(object sender, EventArgs e) { IEnumerable <DBTableInfo> lst = gvTables.DataSource as IEnumerable <DBTableInfo>; if (lst == null) { return; } List <string> selection = new List <string>(); foreach (DBTableInfo info in lst) { if (info.IsGenerate) { selection.Add(info.Name); } } DBInfo db = DbInfo.CreateDBInfo(); using (BatchAction ba = db.DefaultOperate.StarBatchAction()) { using (FrmProcess frmPro = FrmProcess.ShowProcess()) { string file = DesignerInfo.SelectDocView.DocData.FileName; XmlDocument doc = DBEntityInfo.GetClassDiagram(file); frmPro.UpdateProgress(0, 10, "正在读取类信息"); List <DBTableInfo> lstGen = TableChecker.GetTableInfo(db, selection); string entityNamespace = DesignerInfo.GetNameSpace(); for (int i = 0; i < lstGen.Count; i++) { frmPro.UpdateProgress(i, lstGen.Count, "正在生成"); string baseType = cmbBaseType.Text; if (string.IsNullOrEmpty(baseType)) { baseType = GetDefaultBaseType(); } DBEntityInfo info = new DBEntityInfo(entityNamespace, lstGen[i], DesignerInfo, DbInfo, baseType); info.GreanCode(doc); } //拷贝备份 File.Copy(file, file + ".bak", true); EntityMappingConfig.SaveXML(file, doc); } } this.Close(); }
/// <summary> /// 保存XML信息 /// </summary> /// <param name="entity"></param> public static void SaveXML(DBEntityInfo entity) { //string fileName = entity.FileName.Replace(entity.ClassName + ".cs", entity.ClassName + ".be.xml"); FileInfo classFile = new FileInfo(entity.DesignerInfo.SelectDocView.DocData.FileName); string dicName = classFile.DirectoryName + "\\BEM\\"; if (!Directory.Exists(dicName)) { Directory.CreateDirectory(dicName); } string fileName = dicName + entity.ClassName + ".BEM.xml"; XmlDocument doc = ToXML(entity); SaveXML(fileName, doc); EnvDTE.ProjectItem newit = entity.DesignerInfo.CurrentProject.ProjectItems.AddFromFile(fileName); newit.Properties.Item("BuildAction").Value = (int)BuildAction.Resource; }
/// <summary> /// 实体生成XML配置 /// </summary> /// <param name="entity"></param> /// <returns></returns> public static XmlDocument ToXML(DBEntityInfo entity) { XmlDocument doc = NewXmlDocument(); XmlNode classNode = doc.CreateElement("class"); doc.AppendChild(classNode); XmlAttribute att = doc.CreateAttribute("TableName"); att.InnerText = entity.BelongTable.Name; classNode.Attributes.Append(att); att = doc.CreateAttribute("ClassName"); string className = entity.ClassName; att.InnerText = entity.EntityNamespace + "." + className; classNode.Attributes.Append(att); att = doc.CreateAttribute("IsTable"); att.InnerText = entity.BelongTable.IsView?"0":"1"; classNode.Attributes.Append(att); att = doc.CreateAttribute("BelongDB"); att.InnerText = entity.CurrentDBConfigInfo.DbName; classNode.Attributes.Append(att); att = doc.CreateAttribute("UseCache"); att.InnerText = "0"; classNode.Attributes.Append(att); att = doc.CreateAttribute("Description"); att.InnerText = entity.Summary; classNode.Attributes.Append(att); att = doc.CreateAttribute("Lazy");//延迟加载 att.InnerText = "1"; classNode.Attributes.Append(att); AppendPropertyInfo(entity.BelongTable.Params, classNode); AppendRelationInfo(entity.BelongTable.RelationItems, classNode); return(doc); }
public GrneraterBase(DBEntityInfo entity, ClassDesignerInfo info) { _table = entity.ToTableInfo(); _className = entity.ClassName; DesignerInfo = info; _entityBaseTypeName = GetBaseTypeName(entity.BaseType); _entityBaseTypeShortName = GetBaseTypeShortName(entity.BaseType); _entityFileName = entity.FileName; _entityNamespace = entity.EntityNamespace; _baseNamespace = GetBaseTypeNameSpace(entity.BaseType); _BQLEntityNamespace = entity.EntityNamespace + ".BQLEntity"; _businessNamespace = entity.EntityNamespace + ".Business"; _dataAccessNamespace = entity.EntityNamespace + ".DataAccess"; _DBName = entity.CurrentDBConfigInfo.DbName; _dbConfig = entity.CurrentDBConfigInfo; }
/// <summary> /// 填充是否存在的列 /// </summary> private void RefreashExistsInfo() { foreach (DataGridViewRow dr in gvTables.Rows) { string exists = "未生成"; DBTableInfo info = dr.DataBoundItem as DBTableInfo; if (info != null) { string fileName = DBEntityInfo.GetEntityRealFileName(info, _dbInfo, DesignerInfo); try { if (File.Exists(fileName)) { exists = "已生成"; dr.DefaultCellStyle.ForeColor = Color.Red; } } catch { } } dr.Cells["ColExists"].Value = exists; } }
public BQLEntityGenerater(DBEntityInfo config, ClassDesignerInfo info) : base(config, info) { }
/// <summary> /// 生成代码 /// </summary> public void GenerateCode() { //InitDBConfig(); List <string> lstTarget = new List <string>(_lstSource.Count); bool isUsing = true; Dictionary <string, bool> dicUsing = new Dictionary <string, bool>(); Dictionary <int, CodeElementPosition> dicNeedVirtual = NeedVirtual(); for (int i = 0; i < _lstSource.Count; i++) { string str = _lstSource[i]; if (i == _cp.StartLine - 1) { if (str.IndexOf("class") > 0) { if (str.IndexOf(" partial ") < 0) { str = str.Replace("class", "partial class"); } } lstTarget.Add(str); } else if (i == _cp.EndLine - 1) { string space = CutSpace(str) + " "; foreach (EntityParamField param in _eParamFields) { if (param.IsGenerate) { param.AddSource(lstTarget, space); } } foreach (EntityRelationItem relation in _eRelation) { if (relation.IsGenerate) { relation.AddSource(lstTarget, space); } } if (_dbParams != null) { foreach (EntityParam param in _dbParams) { StringBuilder sb = new StringBuilder(); DBEntityInfo.AppendFieldInfo(param, sb); lstTarget.Add(sb.ToString()); } } if (_dbRelations != null) { foreach (TableRelationAttribute er in _dbRelations) { StringBuilder sb = new StringBuilder(); DBEntityInfo.FillRelationsInfo(er, sb); lstTarget.Add(sb.ToString()); } } AddContext(lstTarget); lstTarget.Add(str); } else if (isUsing && str.IndexOf("namespace " + Namespace) >= 0) { AddSqlCommonUsing(dicUsing, lstTarget); lstTarget.Add(str); isUsing = false; } else { if (isUsing) { if (str.IndexOf("using ") >= 0) { dicUsing[str.Trim()] = true; } } if (dicNeedVirtual.ContainsKey(i + 1)) { str = VirtualProperty(str); } lstTarget.Add(str); } } CodeFileHelper.SaveFile(FileName, lstTarget); GenerateExtenCode(); }
public Generate3Tier(DBEntityInfo entity, ClassDesignerInfo info) : base(entity, info) { dmt = new DataAccessMappingConfig(entity, info); }
public DataAccessMappingConfig(DBEntityInfo entity, ClassDesignerInfo info) : base(entity, info) { Init(); }