Click here to Skip to main content
15,886,199 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 75.9K   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 DACCustomFieldsTable
	{
		public DACCustomFieldsTable()
		{
		}
        
		#region Private members
        
		
		private int		xPKTable = -1;

		private string		xTableName = string.Empty;

		
		private DataRow xCustomFieldsTableRow;

		#endregion

		#region Properties
		
		
		public int  PKTable
		{
			get
			{
				return xPKTable;
			}
			set
			{
				xPKTable = value;
			}
		}

		public string  TableName
		{
			get
			{
				return xTableName;
			}
			set
			{
				xTableName = value;
			}
		}

		
		public DataRow CustomFieldsTableRow
		{
			get
			{
				return xCustomFieldsTableRow;
			}
		}
		
		#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("Customfieldstable_INSERT", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter paramPKTable = new SqlParameter("@PKTable", SqlDbType.Int);
			paramPKTable.Direction = ParameterDirection.Output;
			cmd.Parameters.Add(paramPKTable);

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

			int result = cmd.ExecuteNonQuery();
			CloseConnection();
			
			xPKTable = (int)paramPKTable.Value;

			return result > 0;
		}

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

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

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

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

			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsTable");
			adapter.Fill(dt);
			CloseConnection();
			if(dt.Rows.Count > 0)
			{
				DataRow dr = dt.Rows[0];
				xCustomFieldsTableRow = dr;
				
				xPKTable = (int)dr["PKTable"];

				xTableName = dr["TableName"].ToString();

				return true;
			}
			return false;
		}

		public bool ReadByTableName()
		{
			OpenConnection();
			
			SqlCommand cmd = new SqlCommand("CustomFieldsTable_SELECT_ByName", cnn);
			cmd.CommandType = CommandType.StoredProcedure;
				
			SqlParameter param;
			
			param = new SqlParameter("@TableName", SqlDbType.VarChar, 255);
			param.Value = xTableName;
			cmd.Parameters.Add(param);

			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			DataTable dt = new DataTable("CustomFieldsTable");
			adapter.Fill(dt);
			CloseConnection();
			if(dt.Rows.Count > 0)
			{
				DataRow dr = dt.Rows[0];
				xCustomFieldsTableRow = dr;
				
				xPKTable = (int)dr["PKTable"];

				xTableName = dr["TableName"].ToString();

				return true;
			}
			return false;
		
		}
		
		#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