|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.