private void GenerateDbInputModel() { var dt = _dbTable; var nameText = RepositoryNamespace ?? "Aescr.Model"; for (int index = 0; index < dt.Rows.Count;) { DataRow dataRow = dt.Rows[index]; var inputFile = CreateFile(); inputFile.DownloadPath = DownloadPath + "/InputModel"; var viewFile = CreateFile(); viewFile.DownloadPath = DownloadPath + "/ViewModel"; var updateFile = CreateFile(); updateFile.DownloadPath = DownloadPath + "/InputModel"; var namespaceTemplate = inputFile.CreateNamespace(); namespaceTemplate.NamespaceName = nameText; var viewTemplate = namespaceTemplate.DeepClone(); viewFile.AddNamespace(viewTemplate); var updateTemplate = namespaceTemplate.DeepClone(); updateFile.AddNamespace(updateTemplate); ClassTemplate classTemplate = new ClassTemplate(); classTemplate.ClassName = dataRow["表名"].ToString(); classTemplate.ClassName = classTemplate.ClassName.Replace("_", ""); classTemplate.RealName = dataRow["表名"].ToString(); classTemplate.Comment = new Code.Template.CommentTemplate(); classTemplate.Comment.CommentName = dataRow["表说明"].ToString(); do { DataRow tempRow = dt.Rows[index]; var field = new Code.Template.FieldTemplate(); var comment = new Code.Template.CommentTemplate(); field.FieldName = tempRow["字段名"].ToString(); comment.CommentName = tempRow["字段说明"].ToString(); field.DbType = tempRow["类型"].ToString(); field.MaxLength = tempRow["长度"].ToString().ToInt64(); field.MinLength = 0; field.Comment = comment; field.IsProperty = true; field.IsKey = tempRow["主键"].ToString() == "√"; field.CanNull = tempRow["允许空"].ToString() == "√"; if (_dbGenerate.DbType == DataBaseType.MsSQL) { field.FieldTypeName = DbToCsharpType.MsSqlToCsharpType(tempRow["类型"].ToString()); } else if (_dbGenerate.DbType == DataBaseType.MySQL) { field.FieldTypeName = DbToCsharpType.MySqlToCsharpType(tempRow["类型"].ToString()); } if (field.CanNull == false) { classTemplate.AddField(field); var inputClass = classTemplate.DeepClone(); var viewClass = classTemplate.DeepClone(); var updateClass = classTemplate.DeepClone(); inputClass.ClassName = "Input" + inputClass.ClassName; namespaceTemplate.AddClass(inputClass); viewClass.ClassName = "View" + viewClass.ClassName; viewTemplate.AddClass(viewClass); updateClass.ClassName = "Update" + updateClass.ClassName; updateTemplate.AddClass(updateClass); } index++; if (index == dt.Rows.Count) { break; } } while (string.IsNullOrWhiteSpace(dt.Rows[index]["表名"].ToString())); } }