Click here to Skip to main content
15,895,370 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.5K   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 DACCustomFieldsTableColumn
	{
		public DACCustomFieldsTableColumn()
		{
		}
        
		#region Private members
        
		
		private int		xPKColumn = -1;

		private int		xFKTable = -1;

		private string		xColumnName = string.Empty;

		private int		xTypeId = -1;

		private string		xTypeIdColumnName = string.Empty;

		
		private DataRow xCustomFieldsTableColumnRow;

		#endregion

		#region Properties
		
		
		public int  PKColumn
		{
			get
			{
				return xPKColumn;
			}
			set
			{
				xPKColumn = value;
			}
		}

		public int  FKTable
		{
			get
			{
				return xFKTable;
			}
			set
			{
				xFKTable = value;
			}
		}

		public string  ColumnName
		{
			get
			{
				return xColumnName;
			}
			set
			{
				xColumnName = value;
			}
		}

		public int  TypeId
		{
			get
			{
				return xTypeId;
			}
			set
			{
				xTypeId = value;
			}
		}

		public string  TypeIdColumnName
		{
			get
			{
				return xTypeIdColumnName;
			}
			set
			{
				xTypeIdColumnName = value;
			}
		}

		
		public DataRow CustomFieldsTableColumnRow
		{
			get
			{
				return xCustomFieldsTableColumnRow;
			}
		}
		
		#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("Customfieldstablecolumn_INSERT", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter paramPKColumn = new SqlParameter("@PKColumn", SqlDbType.Int);
			paramPKColumn.Direction = ParameterDirection.Output;
			cmd.Parameters.Add(paramPKColumn);

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

			param = new SqlParameter("@ColumnName", SqlDbType.VarChar, 50);
			param.Value = xColumnName;
			cmd.Parameters.Add(param);

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

			param = new SqlParameter("@TypeIdColumnName", SqlDbType.VarChar, 50);
			param.Value = xTypeIdColumnName;
			cmd.Parameters.Add(param);

			int result = cmd.ExecuteNonQuery();
			CloseConnection();
			
			xPKColumn = (int)paramPKColumn.Value;

			return result > 0;
		}
		public bool Edit()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsTableColumn_UPDATE", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param;
			
			param = new SqlParameter("@PKColumn", SqlDbType.Int);
			param.Value = xPKColumn;
			cmd.Parameters.Add(param);

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

			param = new SqlParameter("@ColumnName", SqlDbType.VarChar, 50);
			param.Value = xColumnName;
			cmd.Parameters.Add(param);

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

			param = new SqlParameter("@TypeIdColumnName", SqlDbType.VarChar, 50);
			param.Value = xTypeIdColumnName;
			cmd.Parameters.Add(param);

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

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

			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsTableColumn");
			adapter.Fill(dt);
			CloseConnection();
			if(dt.Rows.Count > 0)
			{
				DataRow dr = dt.Rows[0];
				xCustomFieldsTableColumnRow = dr;
				
				xPKColumn = (int)dr["PKColumn"];

				xFKTable = (int)dr["FKTable"];

				xColumnName = dr["ColumnName"].ToString();

				xTypeId = (int)dr["TypeId"];

				xTypeIdColumnName = dr["TypeIdColumnName"].ToString();

				return true;
			}
			return false;
		}
		
	
		public bool ReadByFKTable()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsTableColumn_SELECT_ByFKTable", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param;
			
			param = new SqlParameter("@FKTable", SqlDbType.Int);
			param.Value = xFKTable;
			cmd.Parameters.Add(param);

			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsTableColumn");
			adapter.Fill(dt);
			CloseConnection();
			if(dt.Rows.Count > 0)
			{
				DataRow dr = dt.Rows[0];
				xCustomFieldsTableColumnRow = dr;
				
				xPKColumn = (int)dr["PKColumn"];

				xFKTable = (int)dr["FKTable"];

				xColumnName = dr["ColumnName"].ToString();

				xTypeId = (int)dr["TypeId"];

				xTypeIdColumnName = dr["TypeIdColumnName"].ToString();

				return true;
			}
			return false;
		}

		public DataTable ReadCustomFieldsTableCustomFieldsTableColumn()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsTableColumn_CustomFieldsTable_S", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param = new SqlParameter("@FKTable", SqlDbType.Int);
			param.Value = xFKTable;
			cmd.Parameters.Add(param);
			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsTable_CustomFieldsTableColumn");
			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