using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CodeCafe.Web;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
///
/// Class to handle all database transactions to the FAQs table.
/// Generated by Code Cafe Class Generator Version 1.0
/// Create date: 4/28/2011 4:03:27 PM
///
public class clsFAQs
{
/****************************************************************************************************/
MSSqlTools db = new MSSqlTools();
SqlDataReader rdr = null;
SqlCommand cmd;
public int fq_id;
public string fq_question;
public string fq_answer;
/****************************************************************************************************/
public clsFAQs()
{
Clear();
}
/****************************************************************************************************/
///
/// Clears all the public variables
///
public void Clear()
{
fq_id = 0;
fq_question = "";
fq_answer = "";
}
/***************************************************************************************************************************************/
///
/// Populates a drop down list with values from the Database
///
///
/// The drop down list to populate all items in the list will be cleared
///
///
/// The Select record ID of a list item
///
///
/// Specifies the type of list
///
public void List(DropDownList List, int SelID, ListTypes ListType)
{
List.Items.Clear();
switch (ListType)
{
case ListTypes.AllowNew:
List.Items.Add(new ListItem("- Add New -", "0"));
break;
case ListTypes.AllowSelect:
List.Items.Add(new ListItem("- Select -", "0"));
break;
case ListTypes.AllowNone:
List.Items.Add(new ListItem("- None -", "0"));
break;
}
try
{
db.DBase.Open();
cmd = new SqlCommand("FAQs_List", db.DBase);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter Error = cmd.Parameters.AddWithValue("@ErrorCode", 0);
Error.Direction = System.Data.ParameterDirection.Output;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
ListItem item = new ListItem(rdr["fq_question"].ToString(), rdr["fq_id"].ToString());
item.Selected = (int.Parse(rdr["fq_id"].ToString()) == SelID);
List.Items.Add(item);
}
rdr.Close();
}
catch (Exception err)
{
Logger.Log(err);
}
finally
{
db.DBase.Close();
}
}
/****************************************************************************************************/
///
/// Loads record specified by ID and populates values into the public variables
///
///
/// Specifies the Primary key value of the record to load
///
///
/// True on successful load
/// False if an error occurs
///
public bool Load(int ContentID)
{
bool result = false;
try
{
db.DBase.Open();
cmd = new SqlCommand("FAQs_LoadByID", db.DBase);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", ContentID);
SqlParameter Error = cmd.Parameters.AddWithValue("@ErrorCode", 0);
Error.Direction = System.Data.ParameterDirection.Output;
rdr = cmd.ExecuteReader();
if (rdr.Read())
{
fq_id = db.ProcessField(rdr["fq_id"], 0);
fq_question = db.ProcessField(rdr["fq_question"], "");
fq_answer = db.ProcessField(rdr["fq_answer"], "");
}
rdr.Close();
result = true;
}
catch (Exception err)
{
Logger.Log(err);
}
finally
{
db.DBase.Close();
}
return result;
}
/****************************************************************************************************/
///
/// Saves values contained in the public variables to a new record if Primary Key ID is 0 or updates
/// an existing record if Primary Key ID > 0
///
///
/// The ID of record saved or updated.
///
public int Save()
{
int result = 0;
try
{
db.DBase.Open();
cmd = new SqlCommand("FAQs_Save", db.DBase);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@fq_id", fq_id);
cmd.Parameters.AddWithValue("@fq_question", fq_question);
cmd.Parameters.AddWithValue("@fq_answer", fq_answer);
SqlParameter Saved = cmd.Parameters.AddWithValue("@SavedID", 0);
Saved.Direction = System.Data.ParameterDirection.Output;
cmd.ExecuteNonQuery();
result = (int)cmd.Parameters["@SavedID"].Value;
}
catch (Exception err)
{
Logger.Log(err);
result = 0;
}
finally
{
db.DBase.Close();
}
return result;
}
/****************************************************************************************************/
///
/// Deletes the record specified by ID
///
///
/// Specifies the Primary key value of the record to delete
///
///
/// True on successful delete
/// False if an error occurs
///
public bool Delete(int ContentID)
{
bool result = false;
try
{
db.DBase.Open();
cmd = new SqlCommand("FAQs_Delete", db.DBase);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", ContentID);
SqlParameter Error = cmd.Parameters.AddWithValue("@ErrorCode", 0);
Error.Direction = System.Data.ParameterDirection.Output;
cmd.ExecuteNonQuery();
result = true;
}
catch (Exception err)
{
Logger.Log(err);
}
finally
{
db.DBase.Close();
}
return result;
}
/****************************************************************************************************/
}