/// <summary> /// 生成实体类 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="dt">实体字段</param> /// <returns></returns> public string EntityBuilder(BaseConfigModel baseConfigModel, DataTable dt) { string databaseLinkID = baseConfigModel.DataBaseLinkId; DataBaseLinkEntity dataBaseLinkEntity = dataBaseLinkService.GetEntity(databaseLinkID); StringBuilder sb = new StringBuilder(); sb.Append("using System;\r\n"); sb.AppendFormat("using {0}.Code;\r\n", AssTag); sb.Append("using System.ComponentModel.DataAnnotations.Schema;\r\n"); sb.Append("using System.ComponentModel.DataAnnotations;\r\n\r\n"); sb.AppendFormat("namespace {0}.Entity." + baseConfigModel.OutputAreas + "\r\n", AssTag); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); if (dataBaseLinkEntity.DbType == "Oracle") { sb.Append(" [Table(\"" + baseConfigModel.DataBaseTableName.ToUpper() + "\")]\r\n"); } sb.Append(" public class " + baseConfigModel.EntityClassName + " : BaseEntity\r\n"); sb.Append(" {\r\n"); sb.Append(" #region 实体成员\r\n"); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow rowItem in dt.Rows) { string column = rowItem["column_name"].ToString(); string remark = rowItem["remark"].ToString(); string datatype = CommHelper.FindModelsType(rowItem["datatype"].ToString()); sb.Append(" /// <summary>\r\n"); sb.Append(" /// " + remark + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <returns></returns>\r\n"); if (dataBaseLinkEntity.DbType == "Oracle") { sb.Append(" [Column(\"" + column.ToUpper() + "\")]\r\n"); } sb.Append(" public " + datatype + " " + column + " { get; set; }\r\n"); } } sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 扩展操作\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 新增调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public override void Create()\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = string.IsNullOrEmpty(Id)?Guid.NewGuid().ToString():Id;\r\n"); sb.Append(" " + IsCreateDate(dt) + ""); sb.Append(" " + IsCreateUserId(dt) + ""); sb.Append(" " + IsCreateUserName(dt) + ""); sb.Append(" this.CreateUserDeptCode = OperatorProvider.Provider.Current().DeptCode;\r\n"); sb.Append(" this.CreateUserOrgCode = OperatorProvider.Provider.Current().OrganizeCode;\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 编辑调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\"></param>\r\n"); sb.Append(" public override void Modify(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = keyValue;\r\n"); sb.Append(" " + IsModifyDate(dt) + ""); sb.Append(" " + IsModifyUserId(dt) + ""); sb.Append(" " + IsModifyUserName(dt) + ""); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}"); return(sb.ToString()); }
/// <summary> /// 生成实体类 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="dt">实体字段</param> /// <returns></returns> public string EntityBuilder(BaseConfigModel baseConfigModel, DataTable dt) { StringBuilder sb = new StringBuilder(); sb.Append("using System;\r\n"); sb.Append("using System.ComponentModel.DataAnnotations.Schema;\r\n"); sb.Append("using LeaRun.Application.Code;\r\n\r\n"); sb.Append("namespace LeaRun.Application.Entity." + baseConfigModel.OutputAreas + "\r\n"); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 版 本\r\n"); sb.Append(" /// Copyright (c) 2013-2016 聚久信息技术有限公司\r\n"); sb.Append(" /// 创 建:" + baseConfigModel.CreateUser + "\r\n"); sb.Append(" /// 日 期:" + baseConfigModel.CreateDate + "\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public class " + baseConfigModel.EntityClassName + " : BaseEntity\r\n"); sb.Append(" {\r\n"); sb.Append(" #region 实体成员\r\n"); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow rowItem in dt.Rows) { string column = rowItem["column"].ToString(); string remark = rowItem["remark"].ToString(); string datatype = CommHelper.FindModelsType(rowItem["datatype"].ToString()); sb.Append(" /// <summary>\r\n"); sb.Append(" /// " + remark + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <returns></returns>\r\n");// sb.Append(" [Column(\"" + column.ToUpper() + "\")]\r\n"); sb.Append(" public " + datatype + " " + column + " { get; set; }\r\n"); } } sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 扩展操作\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 新增调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public override void Create()\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = Guid.NewGuid().ToString();\r\n"); sb.Append(" " + IsCreateDate(dt) + "\r\n"); sb.Append(" " + IsCreateUserId(dt) + "\r\n"); sb.Append(" " + IsCreateUserName(dt) + "\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 编辑调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\"></param>\r\n"); sb.Append(" public override void Modify(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = keyValue;\r\n"); sb.Append(" " + IsModifyDate(dt) + "\r\n"); sb.Append(" " + IsModifyUserId(dt) + "\r\n"); sb.Append(" " + IsModifyUserName(dt) + "\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}"); return(sb.ToString()); }
/// <summary> /// 生成实体类 /// </summary> /// <param name="gridColumnModel"></param> /// <returns></returns> public string EntityBuilder(BaseConfigModel baseConfigModel, DataTable dt) { string strPk = ""; string strCreateDate = ""; string strCreateUserId = ""; string strCreateUserName = ""; string strModifyDate = ""; string strModifyUserId = ""; string strModifyUserName = ""; try { StringBuilder sb = new StringBuilder(); sb.Append("using System;\r\n"); sb.Append("using System.ComponentModel.DataAnnotations.Schema;\r\n"); sb.Append("using LeaRun.Application.Code;\r\n\r\n"); sb.Append("namespace LeaRun.Application.Entity." + baseConfigModel.OutputAreas + "\r\n"); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 版 本 LearunADMS V6.1.2.0\r\n"); sb.Append(" /// Copyright (c) 2013-2016 上海力软信息技术有限公司\r\n"); sb.Append(" /// 创 建:" + baseConfigModel.CreateUser + "\r\n"); sb.Append(" /// 日 期:" + baseConfigModel.CreateDate + "\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public class " + baseConfigModel.EntityClassName + " : BaseEntity\r\n"); sb.Append(" {\r\n"); sb.Append(" #region 实体成员\r\n"); //实体字段 foreach (DataRow rowItem in dt.Rows) { string column = rowItem["f_column"].ToString(); string remark = rowItem["f_remark"].ToString(); string datatype = CommHelper.FindModelsType(rowItem["f_datatype"].ToString()); sb.Append(" /// <summary>\r\n"); sb.Append(" /// " + remark + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <returns></returns>\r\n"); if (baseConfigModel.DataBaseTablePK == column && datatype == "int") { sb.Append(" [DatabaseGenerated(DatabaseGeneratedOption.None)]"); } sb.Append(" [Column(\"" + column.ToString().ToUpper() + "\")]\r\n"); sb.Append(" public " + datatype + " " + column + " { get; set; }\r\n"); #region 判断是否有创建人和修改人字段 if (baseConfigModel.DataBaseTablePK == column && datatype == "string") { strPk = " this." + baseConfigModel.DataBaseTablePK + " = Guid.NewGuid().ToString();\r\n"; } if (column == "F_CreateDate") { strCreateDate = " this.F_CreateDate = DateTime.Now;\r\n"; } if (column == "F_CreateUserId") { strCreateUserId = " this.F_CreateUserId = OperatorProvider.Provider.Current().UserId;\r\n"; } if (column == "F_CreateUserName") { strCreateUserName = "******"; } if (column == "F_ModifyDate") { strModifyDate = " this.F_ModifyDate = DateTime.Now;\r\n"; } if (column == "F_ModifyUserId") { strModifyUserId = " this.F_ModifyUserId = OperatorProvider.Provider.Current().UserId;\r\n"; } if (column == "F_ModifyUserName") { strModifyUserName = "******"; } #endregion } sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 扩展操作\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 新增调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public override void Create()\r\n"); sb.Append(" {\r\n"); sb.Append(strPk); sb.Append(strCreateDate); sb.Append(strCreateUserId); sb.Append(strCreateUserName); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 编辑调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\"></param>\r\n"); sb.Append(" public override void Modify(" + (strPk != "" ? "string" : "int") + " keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = keyValue;\r\n"); sb.Append(strModifyDate); sb.Append(strModifyUserId); sb.Append(strModifyUserName); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}"); return(sb.ToString()); } catch (Exception) { throw; } }