コード例 #1
0
ファイル: CodeWriter.cs プロジェクト: davelondon/dontstayin
		public static string GenerateCommonCodeForPrimaryKey(Table Table)
		{
			string Constructor = @"
		#region Common
 
		public " + Table.Name + @"(SerializationInfo info, StreamingContext context) { this.Bob = new Bob(info, context);  }
		public " + Table.Name + @"()
		{
			this.Bob = new Bob(Bobs.Tables.Defs." + Table.Name + @");
		}
		public " + Table.Name + @"(BobSet bs)
		{
			this.Bob = new Bob(bs.Table, bs);
		}
		public " + Table.Name + @"(" + Table.SinglePrimaryKey.NativeType + @" " + Table.Name + Table.SinglePrimaryKey.Name + @", IBob Parent, object Column)
			: this()
		{
			Bob.GetBobFromParent(" + Table.Name + Table.SinglePrimaryKey.Name + @", Parent.Bob, Column, TablesEnum." + Table.Name + @");
		}
		public " + Table.Name + @"(" + Table.SinglePrimaryKey.NativeType + @" " + Table.Name + Table.SinglePrimaryKey.Name + @")
			: this()
		{
			Bob.GetBobFromPrimaryKey(" + Table.Name + Table.SinglePrimaryKey.Name + @");
		}
		#endregion";

			return Constructor;
		}
コード例 #2
0
ファイル: Column.cs プロジェクト: davelondon/dontstayin
		public Column(Table table, DataRow columnDetail, Dictionary<string, SqlDbType> columnSqlDbTypes)
		{
			this.Table = table;
			this.Name = columnDetail["COLUMN_NAME"] as string;
			this.SqlDbType = columnSqlDbTypes[this.Name];
			this.Length = (int)columnDetail["LENGTH"];
			this.OrdinalPosition = (int)columnDetail["ORDINAL_POSITION"];
			this.IsNullableSqlColumn = (columnDetail["IS_NULLABLE"] as string == "YES");
			this.HasIsNotNullExtendedProperty = (columnDetail["IsNotNull"] as string == "true");
			this.CausesInvalidation = (columnDetail["CausesInvalidation"] as string == "true");

			this.IsIdentity = ((string)columnDetail["TYPE_NAME"]).EndsWith(" identity");
			this.IsComputed = (bool)columnDetail["IsComputed"];

			if (columnDetail["COLUMN_DEF"] != DBNull.Value)
			{
				string colDefault = ((string)columnDetail["COLUMN_DEF"]);
				if (colDefault.ToLower() != "(newid())")
				{
					colDefault = colDefault.Substring(2, colDefault.Length - 4) + GetValueSuffixByType();
				}
				this.ColumnDefault = colDefault;
			}
		}
コード例 #3
0
ファイル: CodeWriter.cs プロジェクト: davelondon/dontstayin
		public static string GenerateCommonCodeForMultiKey(Table Table)
		{
			//needs tidy up
			string Constructor = @"
		#region Common
	 
		public " + Table.Name + @"(SerializationInfo info, StreamingContext context) { this.Bob = new Bob(info, context);}
		public " + Table.Name + @"()
		{
			this.Bob = new Bob(Bobs.Tables.Defs." + Table.Name + @");
		}
		public " + Table.Name + @"(BobSet bs)
		{
			this.Bob = new Bob(Bobs.Tables.Defs." + Table.Name + @", bs);
		}
		public " + Table.Name + @"(IBob Parent, object Column) : this()
		{
			this.Bob.GetBobFromParentSimple(Parent, Column, TablesEnum." + Table.Name + @");
		}";


			bool NeedComma = false;

			string Qs = string.Empty; ;
			string Ps = string.Empty; ;
			foreach (Column Col in Table.Columns)
			{
				if (Col.IsUniqueKey || Col.IsPrimaryKey)
				{
					if (NeedComma)
					{
						Qs += ", ";
						Ps += ", ";
					}

					Qs += "new Q(" + Table.Name + @".Columns." + Col.Name + "," + Col.Name + ")";
					Ps += Col.NativeType + " " + Col.Name;
					NeedComma = true;
				}
			}

			string KeyConstructor = @"
		public " + Table.Name + @"(" + Ps + @") : this()
		{
			this.Bob.GetBobFromPrimaryKeyArray(new Q[] {" + Qs + @"});
		} 
		#endregion";

			return Constructor + KeyConstructor;
		}
コード例 #4
0
ファイル: CodeWriter.cs プロジェクト: davelondon/dontstayin
		public static string GenerateTableDef(Table table)
		{
		//	if (table.Name == "Banner")
		//	{
		//		table.PrintHash();
		//	}
			string tableDefinitionStart = @"
		public override string TableName
		{
			get
			{
				return " + Quotes(table.Name) + @";
			}
		}

		public override string TableCacheKey
		{
			get
			{
				return " + Quotes(table.Hash) + @";
			}
		}

		public override string ColumnName(object ColumnEnum)
		{
			return " + table.Name + @".GetColumnName((" + table.Name + @".Columns)ColumnEnum);
		}

		public override TablesEnum TableEnum
		{
			get
			{
				return TablesEnum." + table.Name + @";
			}
		}

		public override bool HasSinglePrimaryKey
		{
			get
			{
				return " + table.HasSinglePrimaryKey.ToString().ToLower() + @";
			}
		}
";

			if (table.HasSinglePrimaryKey)
			{
				tableDefinitionStart +=
			@"
		public override object SinglePrimaryKey
		{
			get
			{
				return " + table.Name + @".Columns." + table.SinglePrimaryKey.Name + @";
			}
		}
";
			}
			else
			{
				tableDefinitionStart +=
			@"
		public override object SinglePrimaryKey
		{
			get
			{
				return null;
			}
		}
";
			}

			return tableDefinitionStart;

		}
コード例 #5
0
ファイル: CodeWriter.cs プロジェクト: davelondon/dontstayin
		public static string GenerateBobSet(Table table)
		{
			return CodeWriter.RunNVelocityTemplate("Templates.Bobs.Common.BobSet.vm", new Dictionary<string, object>() { { "table", table } });
		}
コード例 #6
0
ファイル: CodeWriter.cs プロジェクト: davelondon/dontstayin
		public static string GenerateTemplate(Table table)
		{


			string Template = string.Empty;

			Template += @"
	#region " + table.Name + @"Template
	/*
	/// This class is automatically-generated from the database. The contents 
	/// should be copied into the correct Bob class and modified to suit. You'll 
	/// probably have to change some int types to enum's etc.

	#region " + table.Name + @"
	/// <summary>
	/// " + table.Description + @"
	/// </summary>
	[Serializable]
	public partial class " + table.Name + @" 
	{
		
		#region Simple members";

			string TemplateBottom = @"
		#endregion

	}
	#endregion

	*/
	#endregion";;

			foreach (Column column in table.Columns)
			{
				if (column.NativeType == "Guid")
				{
					Template += @"
		/// <summary>
		/// " + column.Description + @"
		/// </summary>
		public Guid	" + column.Name + @"
		{
			get{ return Cambro.Misc.Db.GuidConvertor(this[" + table.Name + @".Columns." + column.Name + @"]);}		
			set{ this[" + table.Name + @".Columns." + column.Name + @"] = new System.Data.SqlTypes.SqlGuid(value);}
		}";
				}
				else if (column.IsReadOnly)
				{
					Template += @"
		/// <summary>
		/// " + column.Description + @"
		/// </summary>
		public " + column.NativeType + @" " + column.Name + @"
		{
			get { return (" + column.NativeType + @")this[" + table.Name + @".Columns." + column.Name + @"]; }
		}";
				}
				else
				{
					Template += @"
		/// <summary>
		/// " + column.Description + @"
		/// </summary>
		public override " + column.NativeType + @" " + column.Name + @"
		{
			get { return (" + column.NativeType + @")this[" + table.Name + @".Columns." + column.Name + @"]" + (column.Name == "K" ? " as int? ?? 0 " : "") + @"; }
			set { this[" + table.Name + @".Columns." + column.Name + @"] = value; }
		}";
					
				}

			}

			Template += TemplateBottom;

			return Template;
		}