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
}
}