Click here to Skip to main content
15,895,774 members
Articles / Database Development / SQL Server

DACBuilder – Data Access objects generation tool based on XML and XSL templates transformation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (13 votes)
31 Mar 2006CPOL23 min read 76.6K   1.9K   68  
The DACBuilder application provides auto-generation features from multiple database systems in multiple programming languages.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DACBuilder.CustomFields
{

	public class DACCustomFieldsProperty
	{
		public DACCustomFieldsProperty()
		{
		}
        
		#region Private members
        
		
		private int		xPKProperty = -1;

		private int		xFKPropertyType = -1;

		private int		xFKColumn = -1;

		private string		xDefaultValue = string.Empty;

		private string		xPropertyName = string.Empty;

		private int		xFKPropertyList = -1;

		
		private DataRow xCustomFieldsPropertyRow;

		#endregion

		#region Properties
		
		
		public int  PKProperty
		{
			get
			{
				return xPKProperty;
			}
			set
			{
				xPKProperty = value;
			}
		}

		public int  FKPropertyType
		{
			get
			{
				return xFKPropertyType;
			}
			set
			{
				xFKPropertyType = value;
			}
		}

		public int  FKColumn
		{
			get
			{
				return xFKColumn;
			}
			set
			{
				xFKColumn = value;
			}
		}

		public string  DefaultValue
		{
			get
			{
				return xDefaultValue;
			}
			set
			{
				xDefaultValue = value;
			}
		}

		public string  PropertyName
		{
			get
			{
				return xPropertyName;
			}
			set
			{
				xPropertyName = value;
			}
		}

		public int  FKPropertyList
		{
			get
			{
				return xFKPropertyList;
			}
			set
			{
				xFKPropertyList = value;
			}
		}

		
		public DataRow CustomFieldsPropertyRow
		{
			get
			{
				return xCustomFieldsPropertyRow;
			}
		}
		
		#endregion
		
		#region Connection
		
		
		private string cnnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; 
		private SqlConnection cnn;

		private void OpenConnection()
		{
			cnn = new SqlConnection(cnnString);
			cnn.Open();
		}

		private void CloseConnection()
		{
			cnn.Close();
		}

		public string ConnectionString
		{
			get
			{
				return cnnString;
			}
			set
			{
				cnnString = value;
			}
		}

		
		#endregion
		
		#region Standard methods
		
		

		public bool Add()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsProperty_INSERT", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param;
			
			param = new SqlParameter("@FKPropertyType", SqlDbType.Int);
			param.Value = xFKPropertyType;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@FKColumn", SqlDbType.Int);
			param.Value = xFKColumn;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@DefaultValue", SqlDbType.VarChar, 1000);
			param.Value = xDefaultValue;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@PropertyName", SqlDbType.VarChar, 100);
			param.Value = xPropertyName;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@FKPropertyList", SqlDbType.Int);
			if( xFKPropertyList == -1)
				param.Value = DBNull.Value;
			else
				param.Value = xFKPropertyList;
			cmd.Parameters.Add(param);

			int result = cmd.ExecuteNonQuery();
			CloseConnection();
			
			return result > 0;
		}

		public bool Edit()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsProperty_UPDATE", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param;
			
			param = new SqlParameter("@PKProperty", SqlDbType.Int);
			param.Value = xPKProperty;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@FKPropertyType", SqlDbType.Int);
			param.Value = xFKPropertyType;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@FKColumn", SqlDbType.Int);
			param.Value = xFKColumn;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@DefaultValue", SqlDbType.VarChar, 1000);
			param.Value = xDefaultValue;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@PropertyName", SqlDbType.VarChar, 100);
			param.Value = xPropertyName;
			cmd.Parameters.Add(param);

			param = new SqlParameter("@FKPropertyList", SqlDbType.Int);
			if( xFKPropertyList == -1)
				param.Value = DBNull.Value;
			else
				param.Value = xFKPropertyList;
			cmd.Parameters.Add(param);

			int result = cmd.ExecuteNonQuery();
			CloseConnection();
			return result > 0;
		}
		
		public bool Delete()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsProperty_DELETE", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param;
			
			param = new SqlParameter("@PKProperty", SqlDbType.Int);
			param.Value = xPKProperty;
			cmd.Parameters.Add(param);

			int result = cmd.ExecuteNonQuery();
			CloseConnection();
			return result > 0;
		}

//		public bool DeleteByFKPropertyType()
//		{
//			OpenConnection();
//			
//			SqlCommand cmd = new SqlCommand("CustomFieldsProperty_DELETE_ByPropertyType", cnn);
//			cmd.CommandType = CommandType.StoredProcedure;
//				
//			SqlParameter param;
//			
//			param = new SqlParameter("@FKPropertyType", SqlDbType.Int);
//			param.Value = xFKPropertyType;
//			cmd.Parameters.Add(param);
//
//			int result = cmd.ExecuteNonQuery();
//			CloseConnection();
//			return result > 0;
//		}
				
		public bool Read()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsProperty_SELECT", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param;
			
			param = new SqlParameter("@PKProperty", SqlDbType.Int);
			param.Value = xPKProperty;
			cmd.Parameters.Add(param);

			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsProperty");
			adapter.Fill(dt);
			CloseConnection();
			if(dt.Rows.Count > 0)
			{
				DataRow dr = dt.Rows[0];
				xCustomFieldsPropertyRow = dr;
				
				xPKProperty = (int)dr["PKProperty"];

				xFKPropertyType = (int)dr["FKPropertyType"];

				xFKColumn = (int)dr["FKColumn"];

				xDefaultValue = dr["DefaultValue"].ToString();

				xPropertyName = dr["PropertyName"].ToString();

				xFKPropertyList = dr["FKPropertyList"] == DBNull.Value ? -1 : (int)dr["FKPropertyList"];

				return true;
			}
			return false;
		}



		
		public DataTable ReadCustomFieldsTypeCustomFieldsProperty()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsProperty_CustomFieldsType_S", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param = new SqlParameter("@FKPropertyType", SqlDbType.Int);
			param.Value = xFKPropertyType;
			cmd.Parameters.Add(param);
			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsType_CustomFieldsProperty");
			adapter.Fill(dt);
			CloseConnection();
			return dt;
		}

		public DataTable ReadCustomFieldsTableColumnCustomFieldsProperty()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsProperty_CustomFieldsTableColumn_S", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param = new SqlParameter("@FKColumn", SqlDbType.Int);
			param.Value = xFKColumn;
			cmd.Parameters.Add(param);
			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsTableColumn_CustomFieldsProperty");
			adapter.Fill(dt);
			CloseConnection();
			return dt;
		}

		public DataTable ReadCustomFieldsPropertyListCustomFieldsProperty()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsProperty_CustomFieldsPropertyList_S", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param = new SqlParameter("@FKPropertyList", SqlDbType.Int);
			param.Value = xFKPropertyList;
			cmd.Parameters.Add(param);
			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsPropertyList_CustomFieldsProperty");
			adapter.Fill(dt);
			CloseConnection();
			return dt;
		}

		
		#endregion
		
		
		#region Other DAC logic
		
		#endregion
		
	}
		
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer Telstra Internet
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions