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> /// 更新类信息 /// </summary> /// <param name="ctype"></param> /// <param name="project"></param> /// <param name="currentDiagram"></param> /// <returns></returns> public static EntityConfig GetEntityConfigByTable(ClrType ctype, ClassDesignerInfo desinfo) { EntityConfig entity = new EntityConfig(ctype, desinfo); //entity.DesignerInfo.SelectDocView = selectDocView; if (string.IsNullOrEmpty(entity.TableName)) { return(null); } DBInfo db = entity.DbInfo.CreateDBInfo(); List <string> selTab = new List <string>(); selTab.Add(entity.TableName); List <DBTableInfo> lstGen = TableChecker.GetTableInfo(db, selTab); if (lstGen.Count > 0) { DBTableInfo info = lstGen[0]; Dictionary <string, EntityParamField> dicParam = entity.GetParamMapField(); entity._dbParams = new List <EntityParam>(); foreach (EntityParam prm in info.Params) { string paramName = prm.ParamName; if (dicParam.ContainsKey(paramName)) { continue; } entity._dbParams.Add(prm); } Dictionary <string, EntityRelationItem> dicRelation = entity.GetRelationmMapField(); entity._dbRelations = new List <TableRelationAttribute>(); foreach (TableRelationAttribute tr in info.RelationItems) { string key = EntityFieldBase.ToPascalName(tr.TargetTable) + ":" + EntityFieldBase.ToPascalName(tr.SourceName) + ":" + EntityFieldBase.ToPascalName(tr.TargetName); if (dicRelation.ContainsKey(key)) { continue; } entity._dbRelations.Add(tr); } } return(entity); }