public string ToDataEntityValue() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Concat(new string[] { this.EntityName, " obj", this.EntityName, "= new ", this.EntityName, "();" })); ColumnRuleSchema primaryKey = this.PrimaryKey; foreach (ColumnRuleSchema current in from s in this.Columns where s.FieldName.ToLower().IndexOf("guid") < 0 select s) { if (!current.IsIdentity) { stringBuilder.AppendLine(string.Concat(new string[] { " obj", this.EntityName, ".", current.PropertyName, "=;" })); } } return(stringBuilder.ToString()); }
public string ToInsertReturn() { string result; if (!this.PrimaryKey.IsIdentity) { result = string.Format(Resources.GetInsertNoIdentity, this.EntityMemberName, this.PrimaryKey.PropertyName); } else { ColumnRuleSchema columnRuleSchema = (from s in this.Columns where s.FieldName.ToLower().Contains("guid") select s).FirstOrDefault <ColumnRuleSchema>(); string text = (columnRuleSchema != null) ? string.Concat(new string[] { "SELECT ", this.PrimaryKey.FieldName, " FROM \" + _TableName + \" WHERE ", columnRuleSchema.FieldName, "='\"+", this.EntityMemberName, ".", columnRuleSchema.PropertyName, "+\"' LIMIT 1;" }) : "SELECT LAST_INSERT_ID();"; result = string.Format(Resources.GetInsertIdentity, new object[] { this.EntityMemberName, this.PrimaryKey.PropertyName, text, this.PrimaryKey.GetCSharpSystemType }); } return(result); }
public string ToJavaDataSetEntity(string _NameSpace) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Concat(new string[] { this.EntityName, " ", this.EntityMemberName, "= new ", this.EntityName, "();" })); ColumnRuleSchema primaryKey = this.PrimaryKey; foreach (ColumnRuleSchema current in from s in this.Columns where s.ColumnType != "PrimaryKey" && s.FieldName.ToLower().IndexOf("guid") < 0 select s) { stringBuilder.AppendLine(this.EntityMemberName + ".set" + current.PropertyName + "();"); } return(stringBuilder.ToString()); }
public string ToDataEntityProperties(string _NameSpace) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("using System;"); stringBuilder.AppendLine("using System.Collections;"); stringBuilder.AppendLine("using System.Runtime.Serialization;"); stringBuilder.AppendLine("using WTF.Framework;"); stringBuilder.AppendLine(""); stringBuilder.AppendLine("namespace " + _NameSpace + ".DataEntity"); stringBuilder.AppendLine("{"); stringBuilder.AppendLine(" #region " + this.EntityName); stringBuilder.AppendLine(" /// <summary>"); if (string.IsNullOrEmpty(this.Description)) { stringBuilder.AppendLine(" /// " + this.EntityName); } else { stringBuilder.AppendLine(" /// " + this.Description + " 实体层"); } stringBuilder.AppendLine(" /// </summary>"); stringBuilder.AppendLine(" [Serializable]"); stringBuilder.AppendLine(" public class " + this.EntityName); stringBuilder.AppendLine(" {"); stringBuilder.AppendLine(" #region Constructors "); stringBuilder.AppendLine(" public " + this.EntityName + "()"); stringBuilder.AppendLine(" {"); foreach (ColumnRuleSchema current in this.Columns) { string text = current.FieldName.ToLower(); if (text.IndexOf("guid") >= 0) { stringBuilder.AppendLine(" " + current.PropertyName + " = System.Guid.NewGuid().ToString();"); } else { stringBuilder.AppendLine(string.Concat(new string[] { " ", current.PropertyName, "=", current.DefaultValue, ";" })); } } stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(" #endregion "); stringBuilder.AppendLine(""); stringBuilder.AppendLine(" #region Public Properties "); ColumnRuleSchema primaryKey = this.PrimaryKey; foreach (ColumnRuleSchema current in this.Columns) { string getCSharpSystemType = current.GetCSharpSystemType; stringBuilder.AppendLine(" /// <summary>"); stringBuilder.AppendLine(" /// " + current.FieldName); if (!string.IsNullOrEmpty(current.Description)) { stringBuilder.AppendLine(" /// " + current.Description); } stringBuilder.AppendLine(" /// </summary>"); if (primaryKey != null && primaryKey.FieldName == current.FieldName) { stringBuilder.AppendLine(" [PrimaryKey]"); } stringBuilder.AppendLine(" public " + getCSharpSystemType + " " + current.PropertyName); stringBuilder.AppendLine(" {"); stringBuilder.AppendLine(" get;"); stringBuilder.AppendLine(" set;"); stringBuilder.AppendLine(" }"); } stringBuilder.AppendLine(" #endregion "); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(" #endregion "); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine("}"); return(stringBuilder.ToString()); }
public string ToJavaDataEntity(string _NameSpace) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("import java.util.Date;"); stringBuilder.AppendLine("import com.WTF.core.*;"); stringBuilder.AppendLine("import com.WTF.dal.*;"); stringBuilder.AppendLine("public class " + this.EntityName); stringBuilder.AppendLine("{"); ColumnRuleSchema primaryKey = this.PrimaryKey; foreach (ColumnRuleSchema current in this.Columns) { if (primaryKey != null && primaryKey.FieldName == current.FieldName) { if (primaryKey.IsIdentity) { stringBuilder.AppendLine("\t@ColumnInfo(PrimaryKey=true,Identity=true)"); } else { stringBuilder.AppendLine("\t@ColumnInfo(PrimaryKey=true)"); } } if (current.DataType.Contains("text")) { stringBuilder.AppendLine("\t@ColumnInfo(JdbcType= JdbcType.LONGVARCHAR)"); } stringBuilder.AppendLine(string.Concat(new string[] { "\tprivate ", current.GetJavaSystemType, " ", current.PropertyCamelName, ";" })); stringBuilder.AppendLine("\t/**"); stringBuilder.AppendLine("\t* " + current.Description); stringBuilder.AppendLine("\t* @return "); stringBuilder.AppendLine("\t*/"); stringBuilder.AppendLine(string.Concat(new string[] { "\tpublic ", current.GetJavaSystemType, " get", current.PropertyName, "() {" })); stringBuilder.AppendLine("\t\treturn " + current.PropertyCamelName + ";"); stringBuilder.AppendLine("\t}"); stringBuilder.AppendLine("\t/**"); stringBuilder.AppendLine("\t* " + current.Description); stringBuilder.AppendLine("\t* @param " + current.PropertyCamelName); stringBuilder.AppendLine("\t*/"); stringBuilder.AppendLine(string.Concat(new string[] { "\tpublic void set", current.PropertyName, "(", current.GetJavaSystemType, " ", current.PropertyCamelName, ") {" })); stringBuilder.AppendLine(string.Concat(new string[] { "\t\tthis.", current.PropertyCamelName, " = ", current.PropertyCamelName, ";" })); stringBuilder.AppendLine("\t}"); } stringBuilder.AppendLine("\tpublic " + this.EntityName + "()"); stringBuilder.AppendLine("\t{"); foreach (ColumnRuleSchema current in this.Columns) { string text = current.FieldName.ToLower(); if (text.IndexOf("guid") >= 0) { stringBuilder.AppendLine("\t\t" + current.PropertyCamelName + " = StringHelper.UUID36();"); } else { stringBuilder.AppendLine(string.Concat(new string[] { "\t\t", current.PropertyCamelName, "=", current.DefaultJavaValue, ";" })); } } stringBuilder.AppendLine("\t}"); stringBuilder.AppendLine("}"); return(stringBuilder.ToString()); }
public string ToDataEntity(string _NameSpace) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("using System;"); stringBuilder.AppendLine("using System.Collections;"); stringBuilder.AppendLine("using System.Runtime.Serialization;"); stringBuilder.AppendLine("using WTF.Framework;"); stringBuilder.AppendLine(""); stringBuilder.AppendLine("namespace " + _NameSpace + ".DataEntity"); stringBuilder.AppendLine("{"); stringBuilder.AppendLine(" #region " + this.EntityName); stringBuilder.AppendLine(" /// <summary>"); if (string.IsNullOrEmpty(this.Description)) { stringBuilder.AppendLine(" /// " + this.EntityName); } else { stringBuilder.AppendLine(" /// " + this.Description + " 实体层"); } stringBuilder.AppendLine(" /// </summary>"); stringBuilder.AppendLine(" [Serializable]"); stringBuilder.AppendLine(" public partial class " + this.EntityName); stringBuilder.AppendLine(" {"); stringBuilder.AppendLine(" #region Member Variables "); foreach (ColumnRuleSchema current in this.Columns) { stringBuilder.AppendLine(string.Concat(new string[] { " private System.", current.GetCSharpSystemType, " ", current.MemberName, ";" })); } stringBuilder.AppendLine(" #endregion "); stringBuilder.AppendLine(""); stringBuilder.AppendLine(" #region Constructors "); stringBuilder.AppendLine(" public " + this.EntityName + "()"); stringBuilder.AppendLine(" {"); foreach (ColumnRuleSchema current in this.Columns) { string text = current.FieldName.ToLower(); if (text.IndexOf("guid") >= 0) { stringBuilder.AppendLine(" " + current.MemberName + " = System.Guid.NewGuid().ToString();"); } else { stringBuilder.AppendLine(string.Concat(new string[] { " ", current.MemberName, "=", current.DefaultValue, ";" })); } } stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(" #endregion "); stringBuilder.AppendLine(""); stringBuilder.AppendLine(" #region Public Properties "); ColumnRuleSchema primaryKey = this.PrimaryKey; foreach (ColumnRuleSchema current in this.Columns) { string getCSharpSystemType = current.GetCSharpSystemType; stringBuilder.AppendLine(" /// <summary>"); stringBuilder.AppendLine(" /// " + current.FieldName); if (!string.IsNullOrEmpty(current.Description)) { stringBuilder.AppendLine(" /// " + current.Description); } stringBuilder.AppendLine(" /// </summary>"); if (primaryKey != null && primaryKey.FieldName == current.FieldName) { if (primaryKey.IsIdentity) { stringBuilder.AppendLine(" [PrimaryKey]"); } else { stringBuilder.AppendLine(" [PrimaryKey(false)]"); } } stringBuilder.AppendLine(" public " + getCSharpSystemType + " " + current.PropertyName); stringBuilder.AppendLine(" {"); stringBuilder.AppendLine(" get { return " + current.MemberName + "; }"); if (this.IsCheckFieldLength && getCSharpSystemType == "String" && current.DataType != "text" && current.DataType != "longtext" && current.DataType != "mediumtext") { stringBuilder.AppendLine(string.Concat(new object[] { " set { if (value.Length > ", current.Length, ") ", Environment.NewLine })); stringBuilder.AppendLine(string.Concat(new object[] { "\t \t throw new Exception(\"", current.FieldName, "请小于", current.Length, "位\");" })); stringBuilder.AppendLine("\t \t else"); stringBuilder.AppendLine("\t \t " + current.MemberName + " = value ;}"); } else { stringBuilder.AppendLine(" set { " + current.MemberName + " = value ;}"); } stringBuilder.AppendLine(" }"); if (this.IsMongoDB && primaryKey != null && primaryKey.FieldName == current.FieldName) { stringBuilder.AppendLine(" /// <summary>"); stringBuilder.AppendLine(" ///MongoDB_id"); stringBuilder.AppendLine(" /// </summary>"); stringBuilder.AppendLine(" public " + getCSharpSystemType + " _id"); stringBuilder.AppendLine(" {"); stringBuilder.AppendLine(" get { return " + current.MemberName + "; }"); stringBuilder.AppendLine(" set { " + current.MemberName + " = value ;}"); stringBuilder.AppendLine(" }"); } } stringBuilder.AppendLine(" #endregion "); stringBuilder.AppendLine(" }"); stringBuilder.AppendLine(" #endregion "); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine("}"); return(stringBuilder.ToString()); }