|
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace DACBuilder.CustomFields
{
public class DACCustomFieldsType
{
public DACCustomFieldsType()
{
}
#region Private members
private int xPKType = -1;
private string xTypeName = string.Empty;
private DataRow xCustomfieldstypeRow;
#endregion
#region Properties
public int PKType
{
get
{
return xPKType;
}
set
{
xPKType = value;
}
}
public string TypeName
{
get
{
return xTypeName;
}
set
{
xTypeName = value;
}
}
public DataRow CustomfieldstypeRow
{
get
{
return xCustomfieldstypeRow;
}
}
#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("Customfieldstype_INSERT", cnn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param;
param = new SqlParameter("@PKType", SqlDbType.Int);
param.Value = xPKType;
cmd.Parameters.Add(param);
param = new SqlParameter("@TypeName", SqlDbType.VarChar, 50);
param.Value = xTypeName;
cmd.Parameters.Add(param);
int result = cmd.ExecuteNonQuery();
CloseConnection();
return result > 0;
}
public bool Edit()
{
OpenConnection();
SqlCommand cmd = new SqlCommand("Customfieldstype_UPDATE", cnn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param;
param = new SqlParameter("@PKType", SqlDbType.Int);
param.Value = xPKType;
cmd.Parameters.Add(param);
param = new SqlParameter("@TypeName", SqlDbType.VarChar, 50);
param.Value = xTypeName;
cmd.Parameters.Add(param);
int result = cmd.ExecuteNonQuery();
CloseConnection();
return result > 0;
}
public bool Delete()
{
OpenConnection();
SqlCommand cmd = new SqlCommand("Customfieldstype_DELETE", cnn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param;
param = new SqlParameter("@PKType", SqlDbType.Int);
param.Value = xPKType;
cmd.Parameters.Add(param);
int result = cmd.ExecuteNonQuery();
CloseConnection();
return result > 0;
}
public bool Read()
{
OpenConnection();
SqlCommand cmd = new SqlCommand("Customfieldstype_SELECT", cnn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param;
param = new SqlParameter("@PKType", SqlDbType.Int);
param.Value = xPKType;
cmd.Parameters.Add(param);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
DataTable dt = new DataTable("Customfieldstype");
adapter.Fill(dt);
CloseConnection();
if(dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0];
xCustomfieldstypeRow = dr;
xPKType = (int)dr["PKType"];
xTypeName = dr["TypeName"].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.