public static string InputConvert2(EntityConfig entity) { var code = new StringBuilder(); code.AppendFormat(@" static void ReadFormValue(I{0} entity, FormConvert convert) {{", entity.Name); foreach (PropertyConfig field in entity.PublishProperty.Where(p => !p.IsPrimaryKey)) { switch (field.CsType.ToLower()) { case "short": case "int16": case "int": case "int32": if (field.Nullable) { code.AppendFormat(@" entity.{0} = convert.ToNullInteger(""{0}"");" , field.Name); } else { code.AppendFormat(@" entity.{0} = convert.ToInteger(""{0}"");" , field.Name); } break; case "bigint": case "long": case "int64": if (field.Nullable) { code.AppendFormat(@" entity.{0} = convert.ToNullLong(""{0}"");" , field.Name); } else { code.AppendFormat(@" entity.{0} = convert.ToLong(""{0}"");" , field.Name); } break; case "decimal": case "numeric": if (field.Nullable) { code.AppendFormat(@" entity.{0} = convert.ToNullDecimal(""{0}"");" , field.Name); } else { code.AppendFormat(@" entity.{0} = convert.ToDecimal(""{0}"");" , field.Name); } break; case "real": case "double": if (field.Nullable) { code.AppendFormat(@" entity.{0} = convert.ToNullDouble(""{0}"");" , field.Name); } else { code.AppendFormat(@" entity.{0} = convert.ToDouble(""{0}"");" , field.Name); } break; case "float": if (field.Nullable) { code.AppendFormat(@" entity.{0} = convert.ToNullSingle(""{0}"");" , field.Name); } else { code.AppendFormat(@" entity.{0} = convert.ToSingle(""{0}"");" , field.Name); } break; case "datetime": case "datetime2": if (field.Nullable) { code.AppendFormat(@" entity.{0} = convert.ToNullDateTime(""{0}"");" , field.Name); } else { code.AppendFormat(@" entity.{0} = convert.ToDateTime(""{0}"");" , field.Name); } break; case "bool": case "boolean": if (field.Nullable) { code.AppendFormat(@" entity.{0} = convert.ToNullBoolean(""{0}"");" , field.Name); } else { code.AppendFormat(@" entity.{0} = convert.ToBoolean(""{0}"");" , field.Name); } break; case "guid": case "uniqueidentifier": if (field.Nullable) { code.AppendFormat(@" entity.{0} = convert.ToNullGuid(""{0}"");" , field.Name); } else { code.AppendFormat(@" entity.{0} = convert.ToGuid(""{0}"");" , field.Name); } break; //case "byte": //case "char": //case "nchar": //case "varchar": //case "nvarchar": //case "string": //case "text": default: code.AppendFormat(@" entity.{0} = convert.ToString(""{0}"",{1});" , field.Name , field.Nullable ? "true" : "false"); break; } } code.Append(@" }"); return(code.ToString()); }
/// <summary> /// 读取表与实体关联表,初始化表结构 /// </summary> private static void ImportTable(HSSFWorkbook workbook, EntityConfig entity) { var labelCell = GetCellStyle(workbook, HorizontalAlignment.Left, VerticalAlignment.Center, true, CreateFontStyle(workbook, "宋体", 9, true)); var valueCell = GetCellStyle(workbook, HorizontalAlignment.Left, VerticalAlignment.Center, true, CreateFontStyle(workbook, "宋体")); if (workbook.GetSheet(entity.ReadTableName) != null) { return; } var sheet = workbook.CreateSheet(entity.ReadTableName); int i = 0; sheet.SetColumnWidth(i++, 4000); sheet.SetColumnWidth(i++, 4000); sheet.SetColumnWidth(i++, 2000); sheet.SetColumnWidth(i++, 2000); sheet.SetColumnWidth(i++, 2000); sheet.SetColumnWidth(i++, 2000); sheet.SetColumnWidth(i++, 8000); sheet.SetColumnWidth(i++, 2000); sheet.SetColumnWidth(i++, 2000); sheet.SetColumnWidth(i, 4000); var row = sheet.CreateRow(0); row.HeightInPoints = 20;//行高 row.CreateCell(0).SetCell("TABLE:", labelCell); row.CreateCell(1).SetCellValue(entity.ReadTableName); SetCellRangeAddress(sheet, valueCell, 0, 0, 1, 3); row.CreateCell(4).SetCell("变动时间:", labelCell); SetCellRangeAddress(sheet, labelCell, 0, 0, 4, 5); row.CreateCell(6).SetCell(DateTime.Today.ToLongDateString(), valueCell); SetCellRangeAddress(sheet, valueCell, 0, 0, 6, 9); row = sheet.CreateRow(1); row.HeightInPoints = 20;//行高 row.CreateCell(0).SetCell("中文名:", labelCell); row.CreateCell(1).SetCell(entity.Caption, valueCell); SetCellRangeAddress(sheet, valueCell, 1, 1, 1, 3); row.CreateCell(4).SetCell("变动类型:", labelCell); SetCellRangeAddress(sheet, labelCell, 1, 1, 4, 5); row.CreateCell(6).SetCell("新建", valueCell); SetCellRangeAddress(sheet, valueCell, 1, 1, 6, 9); row = sheet.CreateRow(3); row.HeightInPoints = 20;//行高 i = 0; row.CreateCell(i++).SetCell("字段", labelCell); row.CreateCell(i++).SetCell("字段类型", labelCell); row.CreateCell(i++).SetCell("长度", labelCell); row.CreateCell(i++).SetCell("可为空", labelCell); row.CreateCell(i++).SetCell("主键", labelCell); row.CreateCell(i++).SetCell("默认值", labelCell); row.CreateCell(i++).SetCell("备注", labelCell); row.CreateCell(i++).SetCell("外键", labelCell); row.CreateCell(i++).SetCell("索引", labelCell); row.CreateCell(i).SetCell("更新时间", labelCell); var fields = entity.PublishProperty.ToArray(); for (int line = 0; line < fields.Length; line++) { var field = fields[line]; row = sheet.CreateRow(line + 4); row.HeightInPoints = 20;//行高 i = 0; row.CreateCell(i++).SetCell(field.ColumnName, valueCell); row.CreateCell(i++).SetCell(field.DbType.ToUpper(), valueCell); row.CreateCell(i++).SetCell(field.CsType == "decimal" ? "(18,4)" : (field.Datalen > 0 ? field.Datalen.ToString() : "-"), valueCell); row.CreateCell(i++).SetCell(field.DbNullable ? "是" : "否", valueCell); row.CreateCell(i++).SetCell(field.IsPrimaryKey ? "是" : "否", valueCell); row.CreateCell(i++).SetCell(field.Nullable ? field.Initialization : "0", valueCell); row.CreateCell(i++).SetCell(field.Caption + ":" + field.Description, valueCell); row.CreateCell(i++).SetCell("未指定", valueCell); row.CreateCell(i++).SetCell(field.CreateIndex ? "是" : "否", valueCell); row.CreateCell(i).SetCell("", valueCell); } }