private void LoadTableSchema(string ConnectionStringName) { if (!string.IsNullOrWhiteSpace(ConnectionStringName)) { this.gvdTables.AutoGenerateColumns = false; this._ConnectionString = this._CodeConfigHelper.GetConnectionString(ConnectionStringName, out this._Database); try { this._TableRuleSchemaList = SqlSchemaHelper.GetAllRuleTables(this._Database, this._ConnectionString, true); this._TableRuleSchemaList = (from x in this._TableRuleSchemaList where this._BusinessNodeInfoList.Keys.Contains(x.TableName) select x).ToList <TableRuleSchema>(); foreach (TableRuleSchema current in this._TableRuleSchemaList) { BusinessNodeInfo objBusinessNodeInfo = this._BusinessNodeInfoList[current.TableName]; current.IsCreate = true; CodeConfigHelper.BusinessNodeToTableRuleSchema(objBusinessNodeInfo, current); } this.gvdTables.DataSource = this._TableRuleSchemaList; } catch (Exception ex) { MessageBox.Show("加载表错误,异常信息:" + ex.ToString()); } } }
private void gvdTables_CellClick(object sender, DataGridViewCellEventArgs e) { if (this.gvdTables.Columns[e.ColumnIndex].Name == "SetCheck") { if (!string.IsNullOrEmpty(this.CurrentEditTable)) { List <ColumnRuleSchema> columns = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == this.CurrentEditTable).Columns; IEnumerator enumerator = ((IEnumerable)this.gvwTableCols.Rows).GetEnumerator(); { while (enumerator.MoveNext()) { DataGridViewRow dataGridViewRow = (DataGridViewRow)enumerator.Current; string FieldName = dataGridViewRow.ReadCell("FieldName", ""); ColumnRuleSchema columnRuleSchema = columns.First((ColumnRuleSchema s) => s.FieldName == FieldName); columnRuleSchema.IsXmlField = this.CheckIsXmlField(columnRuleSchema, dataGridViewRow); columnRuleSchema.IsCheck = bool.Parse(dataGridViewRow.ReadCell("IsCheck", "")); columnRuleSchema.ErrorMessage = dataGridViewRow.ReadCell("ErrorMessage", ""); columnRuleSchema.FieldTitle = dataGridViewRow.ReadCell("FieldTitle", ""); } } } string TableName = this.gvdTables.Rows[e.RowIndex].ReadCell("TableName", ""); this.CurrentEditTable = TableName; TableRuleSchema tableRuleSchema = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == TableName); if (tableRuleSchema.Columns.Count == 0) { tableRuleSchema.Columns = SqlSchemaHelper.GetTableRuleColumnsSchema(this._ConnectionString, this._Database, TableName, this._CodeConfigHelper); } this.gvwTableCols.AutoGenerateColumns = false; this.gvwTableCols.DataSource = tableRuleSchema.Columns; } }
private void LoadTableSchema(string ConnectionStringName) { if (!string.IsNullOrWhiteSpace(ConnectionStringName)) { this.gvdTables.AutoGenerateColumns = false; this._ConnectionString = this._CodeConfigHelper.GetConnectionString(ConnectionStringName, out this._Database); try { this._TableRuleSchemaList = SqlSchemaHelper.GetAllRuleTables(this._Database, this._ConnectionString, !this.IsView.Checked); List <BusinessNodeInfo> business = this._CodeConfigHelper.GetBusiness(); using (List <TableRuleSchema> .Enumerator enumerator = this._TableRuleSchemaList.GetEnumerator()) { while (enumerator.MoveNext()) { TableRuleSchema objTableRuleSchema = enumerator.Current; BusinessNodeInfo objBusinessNodeInfo = business.FirstOrDefault((BusinessNodeInfo s) => s.TableName == objTableRuleSchema.TableName); CodeConfigHelper.BusinessNodeToTableRuleSchema(objBusinessNodeInfo, objTableRuleSchema); } } this.gvdTables.DataSource = this._TableRuleSchemaList; } catch (Exception ex) { MessageBox.Show("加载表错误,异常信息:" + ex.ToString()); } } }
private void btnRuleCode_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.CurrentEditTable)) { List <ColumnRuleSchema> columns = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == this.CurrentEditTable).Columns; IEnumerator enumerator = ((IEnumerable)this.gvwTableCols.Rows).GetEnumerator(); { while (enumerator.MoveNext()) { DataGridViewRow dataGridViewRow = (DataGridViewRow)enumerator.Current; string FieldName = dataGridViewRow.ReadCell("FieldName", ""); ColumnRuleSchema columnRuleSchema = columns.First((ColumnRuleSchema s) => s.FieldName == FieldName); columnRuleSchema.IsXmlField = this.CheckIsXmlField(columnRuleSchema, dataGridViewRow); columnRuleSchema.IsCheck = bool.Parse(dataGridViewRow.ReadCell("IsCheck", "")); columnRuleSchema.ErrorMessage = dataGridViewRow.ReadCell("ErrorMessage", ""); columnRuleSchema.FieldTitle = dataGridViewRow.ReadCell("FieldTitle", ""); } } } IEnumerator enumerator2 = ((IEnumerable)this.gvdTables.Rows).GetEnumerator(); { while (enumerator2.MoveNext()) { DataGridViewRow dataGridViewRow = (DataGridViewRow)enumerator2.Current; string TableName = dataGridViewRow.ReadCell("TableName", ""); TableRuleSchema tableRuleSchema = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == TableName); tableRuleSchema.IsCreate = bool.Parse(dataGridViewRow.ReadCell("IsCreate", "")); tableRuleSchema.Description = dataGridViewRow.ReadCell("Description", ""); tableRuleSchema.EntityName = dataGridViewRow.ReadCell("EntityName", ""); tableRuleSchema.IsMongoDB = bool.Parse(dataGridViewRow.ReadCell("IsMongoDB", "")); tableRuleSchema.IsCheckFieldLength = bool.Parse(dataGridViewRow.ReadCell("IsCheckFieldLength", "")); tableRuleSchema.ConnectionKeyOrConnectionString = dataGridViewRow.ReadCell("ConnectionKeyOrConnectionString", ""); tableRuleSchema.LogModuleType = dataGridViewRow.ReadCell("LogModuleType", ""); tableRuleSchema.UIProjectName = dataGridViewRow.ReadCell("UIProjectName", this.txtUIProjectName.Text); tableRuleSchema.UIProjectPath = dataGridViewRow.ReadCell("UIProjectPath", this.txtUIProjectPath.Text); if (tableRuleSchema.IsCreate && tableRuleSchema.Columns.Count == 0) { tableRuleSchema.Columns = SqlSchemaHelper.GetTableRuleColumnsSchema(this._ConnectionString, this._Database, tableRuleSchema.TableName, this._CodeConfigHelper); } } } int num = (from s in this._TableRuleSchemaList where s.IsCreate select s).Count <TableRuleSchema>(); if (num == 0) { MessageBox.Show("请要生成的表"); } else { this._CodeConfigHelper.UpdateXml((from s in this._TableRuleSchemaList where s.IsCreate select s).ToList <TableRuleSchema>(), this.boxConnectString.SelectedItem.ToString()); MessageBox.Show("一键生成配置文件成功"); } }
public SqlRuleCodeForm(SelectFileInfo objSelectFileInfo) { this.InitializeComponent(); this._SelectFileInfo = objSelectFileInfo; this._CodeConfigHelper = new CodeConfigHelper(objSelectFileInfo.CodeConfigPath); if (this._CodeConfigHelper.LoadCodeConfigXml()) { this.txtConnectionKey.Text = this._CodeConfigHelper.GetBusinessNodeInfoExistsConnectionString(); this._CodeConfigHelper.InitConnectionStrings(this.boxConnectString); this.LoadTableSchema(this.boxConnectString.SelectedItem.ToString()); this.boxLogType.Items.Clear(); foreach (DataRow dataRow in SqlSchemaHelper.GetLogType(objSelectFileInfo.WTFConfigPath).Rows) { this.boxLogType.Items.Add(dataRow["ModuleTypeCode"].ToString()); } this.boxLogType.SelectedItem = this._CodeConfigHelper.GetBusinessNodeInfoExistsLogModuleType(); } }
private void btnLoadColumn_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtModuleID.Text)) { MessageBox.Show("请输入模块标识"); } else { string schemaName = ""; string connectionString = this._CodeConfigHelper.GetConnectionString(this._BusinessNodeInfo.ConnectionKey, out schemaName); this._TableListSchema = SqlSchemaHelper.GetTableListSchema(schemaName, this._BusinessNodeInfo.TableName, this.txtModuleID.Text, this.txtEditUrl.Text, connectionString, this._CodeConfigHelper, this._SelectFileInfo.WTFConfigPath); this.gvdCommand.AutoGenerateColumns = false; this.gvdCommand.DataSource = (from s in this._TableListSchema.Commands orderby s.SortIndex select s).ToList <CommandSchema>(); this.gvdTableCols.AutoGenerateColumns = false; this.gvdTableCols.DataSource = (from s in this._TableListSchema.Columns where !s.FieldName.ToLower().Contains("guid") select s).ToList <ColumnListSchema>(); } }
private void btnLoad_Click(object sender, EventArgs e) { try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("SERVER=" + this.txtServerIP.Text + ";"); stringBuilder.Append("Port=" + this.txtPort.Text + ";"); stringBuilder.Append("user id=" + this.txtUserID.Text + ";"); stringBuilder.Append("password="******";"); stringBuilder.Append("persist security info=True;Allow User Variables=True;Charset=utf8; "); string codeConnectionString = stringBuilder.ToString(); DataTable allSchemata = SqlSchemaHelper.GetAllSchemata(codeConnectionString); this.boxDataBase.Items.Clear(); foreach (DataRow dataRow in allSchemata.Rows) { this.boxDataBase.Items.Add(dataRow["SCHEMA_NAME"]); } } catch (Exception ex) { MessageBox.Show("加载库出错" + ex.Message); } }
public SqlEditForm(SelectFileInfo objSelectFileInfo, BusinessNodeInfo objBusinessNodeInfo) { this.InitializeComponent(); this._SelectFileInfo = objSelectFileInfo; this._CodeConfigHelper = new CodeConfigHelper(objSelectFileInfo.CodeConfigPath); if (this._CodeConfigHelper.LoadCodeConfigXml()) { this._BusinessNodeInfo = objBusinessNodeInfo; this.Text = this._BusinessNodeInfo.TableName + "编辑界面生成"; string text = ""; string text2 = ""; this._CodeConfigHelper.GetBusinessNodeInfoUIPath(objBusinessNodeInfo, out text, out text2); this.txtUIProjectPath.Text = text; this.txtUIProjectName.Text = text2; this.txtBackUrl.Text = (string.IsNullOrWhiteSpace(this._BusinessNodeInfo.ListUrl) ? (objBusinessNodeInfo.EntityName + "List.aspx") : this._BusinessNodeInfo.ListUrl); this.gvdData.AutoGenerateColumns = false; string schemaName = ""; string connectionString = this._CodeConfigHelper.GetConnectionString(this._BusinessNodeInfo.ConnectionKey, out schemaName); this._CurrentColumnList = SqlSchemaHelper.GetTableColumnsSchema(schemaName, this._BusinessNodeInfo.TableName, this._CodeConfigHelper, connectionString); this.gvdData.DataSource = (from s in this._CurrentColumnList where s.ColumnType == "Common" && !s.FieldName.ToLower().Contains("guid") select s).ToList <ColumnEditSchema>(); } }
public TableRuleSchema CreateItemTableRuleSchema(SelectFileInfo objSelectFileInfo) { TableRuleSchema result; if (!objSelectFileInfo.IsExistsCodeConfig()) { result = null; } else { string itemPathEntityName = objSelectFileInfo.GetItemPathEntityName(); if (string.IsNullOrWhiteSpace(itemPathEntityName)) { MessageBox.Show(objSelectFileInfo.ItemFileName + ".cs,不是基础业务层类,因此无法更新或新增"); result = null; } else { CodeConfigHelper codeConfigHelper = new CodeConfigHelper(objSelectFileInfo.CodeConfigPath); if (!codeConfigHelper.LoadCodeConfigXml()) { result = null; } else { BusinessNodeInfo business = codeConfigHelper.GetBusiness(itemPathEntityName); if (business == null) { if (MessageBox.Show(itemPathEntityName + "实体未配置业务XML?是否配置吗?", "", MessageBoxButtons.OKCancel) != DialogResult.OK) { result = null; } else { Dictionary <string, BusinessNodeInfo> dictionary = new Dictionary <string, BusinessNodeInfo>(); BusinessNodeInfo readFileBusinessNodeInfo = CodeConfigHelper.GetReadFileBusinessNodeInfo(itemPathEntityName, objSelectFileInfo.ProjectPath); if (readFileBusinessNodeInfo == null) { MessageBox.Show(objSelectFileInfo.ItemFileName + ".cs,不是基础业务层类,因此无法配置XML"); result = null; } else { dictionary.Add(readFileBusinessNodeInfo.TableName, readFileBusinessNodeInfo); AKeyAddCodeConfig aKeyAddCodeConfig = new AKeyAddCodeConfig(objSelectFileInfo, dictionary); aKeyAddCodeConfig.Show(); result = null; } } } else { string schemaName = ""; string connectionString = codeConfigHelper.GetConnectionString(business.ConnectionKey, out schemaName); if (string.IsNullOrWhiteSpace(connectionString)) { if (MessageBox.Show("连接串键值(" + business.ConnectionKey + ")不存在,要配置连接吗?", "", MessageBoxButtons.OKCancel) == DialogResult.OK) { ConnectConfigFrom connectConfigFrom = new ConnectConfigFrom(objSelectFileInfo); connectConfigFrom.Show(); } result = null; } else { string tableName = business.TableName; try { TableRuleSchema tableRuleSchema = SqlSchemaHelper.GetAllRuleTables(schemaName, connectionString, true).FirstOrDefault((TableRuleSchema s) => s.TableName == tableName); if (tableRuleSchema == null) { MessageBox.Show("数据库找不到此:" + tableName + ",请检查配置是否正确"); result = null; } else { CodeConfigHelper.BusinessNodeToTableRuleSchema(business, tableRuleSchema); tableRuleSchema.Columns = SqlSchemaHelper.GetTableRuleColumnsSchema(connectionString, schemaName, tableRuleSchema.TableName, codeConfigHelper); result = tableRuleSchema; } } catch (Exception ex) { MessageBox.Show("更新代码出现异常,异常错误:" + ex.ToString()); result = null; } } } } } } return(result); }
/// <summary> /// Run the validation. /// </summary> /// <param name="context">The DbContext (code-first) database context.</param> /// <param name="options">A list of options.</param> public static IEnumerable <string> Run(DbContext context, EfModelCheckOptions options) { // Retrieve the model and all of its currently defined mappings etc. EfMappingHelper mapping = new EfMappingHelper(context); // TABLES... // // Get all of the table information, both from the database and the model. List <SqlTable> allSqlTables; List <string> allMappedTables; // Apply schema filter if supplied. if (!string.IsNullOrEmpty(options.DatabaseSchemaName)) { allSqlTables = SqlSchemaHelper.GetSqlTables(context) .Where(t => t.SchemaName == options.DatabaseSchemaName).ToList(); allMappedTables = mapping.Tables .Where(tm => tm.SchemaName == options.DatabaseSchemaName) .Select(t => t.SchemaName + "." + t.TableName).ToList(); } else { allSqlTables = SqlSchemaHelper.GetSqlTables(context).ToList(); allMappedTables = mapping.Tables.Select(t => t.SchemaName + "." + t.TableName).ToList(); } // Set up list of messages that we will return at the end. List <string> errors = new List <string>(); // ...IN THE DATABASE BUT NOT IN THE MODEL if (options.CheckForTablesInDatabaseButNotInModel) { List <string> tablesInDatabaseButNotInModel = allSqlTables.Select(t => t.SchemaName + "." + t.TableName).Except(allMappedTables).ToList(); errors.AddRange(tablesInDatabaseButNotInModel .Select(table => $"The table {table} is in the database but not in the entity model.")); } // ...IN THE MODEL BUT NOT IN THE DATABASE if (options.CheckForTablesInModelButNotInDatabase) { List <string> tablesInModelButNotInDatabase = allMappedTables.Except(allSqlTables.Select(t => t.SchemaName + "." + t.TableName)).ToList(); errors.AddRange(tablesInModelButNotInDatabase.Select(table => $"The table {table} is in the model but not in the database.").ToList()); } // COLUMNS... // // Now validate all of the columns in all of the entities. foreach (EfEntityMapping entityMapping in mapping.EntityMappings) { IEnumerable <EfTableMapping> tableMappings = options.DatabaseSchemaName != string.Empty ? entityMapping.TableMappings.Where(t => t.SchemaName == options.DatabaseSchemaName) : entityMapping.TableMappings; foreach (EfTableMapping tableMapping in tableMappings) { // Retrieve the columns for this particular table directly from the database. List <SqlColumn> sqlColumns = SqlSchemaHelper.GetTableSqlColumns(context, tableMapping.TableName, options.DatabaseSchemaName).ToList(); if (options.CheckForColumnsInDatabaseButNotInModel) { // ...IN THE DATABASE BUT NOT IN THE MODEL errors.AddRange(from sqlColumn in sqlColumns let columnNames = (from t in tableMapping.PropertyMappings select t.ColumnName).ToList() where !columnNames.Contains(sqlColumn.ColumnName) select $"The column {sqlColumn.ColumnName} in table {tableMapping.TableName} is not in the entity model."); } if (options.CheckForColumnsInModelButNotInDatabase) { // Look through all of the properties of the entity. foreach (EfPropertyMapping propertyMapping in tableMapping.PropertyMappings) { // ...IN THE MODEL BUT NOT IN THE DATABASE if (sqlColumns.All(c => c.ColumnName != propertyMapping.ColumnName)) { errors.Add($"The column {propertyMapping.ColumnName} doesn't exist in the table {tableMapping.TableName}."); } SqlColumn column = sqlColumns.SingleOrDefault(c => c.ColumnName == propertyMapping.ColumnName); if (column != null) { // Check that the column is the correct data type. if (column.DataType == null) { errors.Add( $"The column {propertyMapping.ColumnName} in table {tableMapping.TableName} has an unknown data type of {propertyMapping.PropertyType.Name}."); } if (column.DataType != null && propertyMapping.PropertyType != column.DataType) { errors.Add( $"The column {propertyMapping.ColumnName} in table {tableMapping.TableName} has a data type of {propertyMapping.PropertyType.Name} which does not match with the database ({column.DataType.Name})."); } // Check that the nullable status of the column agrees with the database. if (column.IsNullable & !propertyMapping.IsNullable) { errors.Add( $"The column {propertyMapping.ColumnName} in table {tableMapping.TableName} is nullable, but the {propertyMapping.PropertyType.Name} property is not nullable."); } if (!column.IsNullable & propertyMapping.IsNullable) { errors.Add( $"The column {propertyMapping.ColumnName} in table {tableMapping.TableName} is not nullable, but the {propertyMapping.PropertyType.Name} property is nullable."); } // Check that "MaxLength" property (where appropriate) of the column agrees with the database. if (column.MaximumLength != propertyMapping.MaximumLength) { errors.Add( $"The column {propertyMapping.ColumnName} in table {tableMapping.TableName} has a maximum length which does not agree with the {propertyMapping.PropertyType.Name} property."); } } } } } } // PRIMARY/FOREIGN KEY RELATIONSHIPS... // // Retrieve all primary/foreign key relationships directly from the database. List <SqlRelationship> sqlRelationships = SqlSchemaHelper.GetSqlRelationships(context).ToList(); // Group these relationships by the name of the Foreign Key so that composite foreign keys can be grouped together. List <IGrouping <string, SqlRelationship> > sqlRelationshipGroups = sqlRelationships.GroupBy(s => s.ForeignKeyName).ToList(); // ...IN THE DATABASE BUT NOT IN THE MODEL if (options.CheckForRelationshipsInDatabaseButNotInModel) { foreach (IGrouping <string, SqlRelationship> sqlRelationshipGroup in sqlRelationshipGroups) { // For this group, retrieve the list of properties of to/from. string[] fromProperties = sqlRelationshipGroup.OrderBy(g => g.OrdinalPosition).Select(g => g.PrimaryKeyColumnName).ToArray(); string[] toProperties = sqlRelationshipGroup.OrderBy(g => g.OrdinalPosition).Select(g => g.ForeignKeyColumnName).ToArray(); string fromTable = sqlRelationshipGroup.First().PrimaryKeyTableName; string toTable = sqlRelationshipGroup.First().ForeignKeyTableName; if (!mapping.RelationshipMappings.Any(relationship => fromTable == relationship.FromTable && toTable == relationship.ToTable && fromProperties.SequenceEqual(relationship.FromProperties) && toProperties.SequenceEqual(relationship.ToProperties))) { errors.Add( $"The relationship between {fromTable} and {toTable} from keys {string.Join(",", fromProperties)} to {string.Join(",", toProperties)} is in the database but not in the entity model."); } } } if (options.CheckForRelationshipsInModelButNotInDatabase) { // ...IN THE MODEL BUT NOT IN THE DATABASE foreach (EfRelationshipMapping relationshipMapping in mapping.RelationshipMappings) { bool match = false; foreach (IGrouping <string, SqlRelationship> sqlRelationshipGroup in sqlRelationshipGroups) { // For this group, retrieve the list of properties of to/from. string[] fromProperties = sqlRelationshipGroup.OrderBy(g => g.OrdinalPosition).Select(g => g.PrimaryKeyColumnName).ToArray(); string[] toProperties = sqlRelationshipGroup.OrderBy(g => g.OrdinalPosition).Select(g => g.ForeignKeyColumnName).ToArray(); if (sqlRelationshipGroup.Any(sqlRelationship => sqlRelationship.PrimaryKeyTableName == relationshipMapping.FromTable && sqlRelationship.ForeignKeyTableName == relationshipMapping.ToTable && fromProperties.SequenceEqual(relationshipMapping.FromProperties) && toProperties.SequenceEqual(relationshipMapping.ToProperties))) { match = true; break; } } if (!match) { errors.Add( $"The relationship between {relationshipMapping.FromTable} and {relationshipMapping.ToTable} from keys {string.Join(",", relationshipMapping.FromProperties)} to {string.Join(",", relationshipMapping.ToProperties)} is not in the database."); } } } return(errors.ToArray()); }
private List <TableRuleSchema> ProcessData() { if (!string.IsNullOrEmpty(this.CurrentEditTable)) { List <ColumnRuleSchema> columns = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == this.CurrentEditTable).Columns; IEnumerator enumerator = ((IEnumerable)this.gvwTableCols.Rows).GetEnumerator(); while (enumerator.MoveNext()) { DataGridViewRow dataGridViewRow = (DataGridViewRow)enumerator.Current; string FieldName = dataGridViewRow.ReadCell("FieldName", ""); ColumnRuleSchema columnRuleSchema = columns.First((ColumnRuleSchema s) => s.FieldName == FieldName); columnRuleSchema.IsXmlField = this.CheckIsXmlField(columnRuleSchema, dataGridViewRow); columnRuleSchema.IsCheck = bool.Parse(dataGridViewRow.ReadCell("IsCheck", "")); columnRuleSchema.ErrorMessage = dataGridViewRow.ReadCell("ErrorMessage", ""); columnRuleSchema.FieldTitle = dataGridViewRow.ReadCell("FieldTitle", ""); } } List <TableRuleSchema> result; IEnumerator enumerator2 = ((IEnumerable)this.gvdTables.Rows).GetEnumerator(); while (enumerator2.MoveNext()) { DataGridViewRow dataGridViewRow = (DataGridViewRow)enumerator2.Current; string TableName = dataGridViewRow.ReadCell("TableName", ""); string text = dataGridViewRow.ReadCell("LogModuleType", ""); text = (string.IsNullOrWhiteSpace(text) ? ((this.boxLogType.SelectedItem == null) ? "" : this.boxLogType.SelectedItem.ToString()) : text); string text2 = dataGridViewRow.ReadCell("ConnectionKeyOrConnectionString", ""); text2 = (string.IsNullOrWhiteSpace(text2) ? this.txtConnectionKey.Text : text2); TableRuleSchema tableRuleSchema = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == TableName); tableRuleSchema.IsCreate = bool.Parse(dataGridViewRow.ReadCell("IsCreate", "")); tableRuleSchema.Description = dataGridViewRow.ReadCell("Description", ""); tableRuleSchema.EntityName = dataGridViewRow.ReadCell("EntityName", ""); tableRuleSchema.IsMongoDB = bool.Parse(dataGridViewRow.ReadCell("IsMongoDB", "")); tableRuleSchema.IsCheckFieldLength = bool.Parse(dataGridViewRow.ReadCell("IsCheckFieldLength", "")); tableRuleSchema.ConnectionKeyOrConnectionString = text2; tableRuleSchema.LogModuleType = text; if (tableRuleSchema.IsCreate && string.IsNullOrWhiteSpace(tableRuleSchema.LogModuleType)) { MessageBox.Show("表名:" + TableName + ",请输入日志类型或选择日志类型"); result = null; return(result); } if (tableRuleSchema.IsCreate && tableRuleSchema.Columns.Count == 0) { tableRuleSchema.Columns = SqlSchemaHelper.GetTableRuleColumnsSchema(this._ConnectionString, this._Database, tableRuleSchema.TableName, this._CodeConfigHelper); } } List <TableRuleSchema> list = (from s in this._TableRuleSchemaList where s.IsCreate select s).ToList <TableRuleSchema>(); if (list.Count <TableRuleSchema>() == 0) { MessageBox.Show("请选择表"); result = null; } else { result = list; } return(result); }