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 ProductInfo table. /// Generated by Code Cafe Class Generator Version 1.0 /// Create date: 5/2/2011 3:43:18 PM /// public class clsProductInfo { /****************************************************************************************************/ MSSqlTools db = new MSSqlTools(); SqlDataReader rdr = null; SqlCommand cmd; public int pi_id; public string pi_name; public string pi_description; public float pi_price; public bool pi_recurring; /****************************************************************************************************/ public clsProductInfo() { Clear(); } /****************************************************************************************************/ /// /// Clears all the public variables /// public void Clear() { pi_id = 0; pi_name = ""; pi_description = ""; pi_price = 0; pi_recurring = false; } /***************************************************************************************************************************************/ /// /// 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("ProductInfo_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["pi_name"].ToString(), rdr["pi_id"].ToString()); item.Selected = (int.Parse(rdr["pi_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("ProductInfo_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()) { pi_id = db.ProcessField(rdr["pi_id"], 0); pi_name = db.ProcessField(rdr["pi_name"], ""); pi_description = db.ProcessField(rdr["pi_description"], ""); pi_price = db.ProcessField(rdr["pi_price"], 0); pi_recurring = db.ProcessField(rdr["pi_recurring"], false); } 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("ProductInfo_Save", db.DBase); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pi_id", pi_id); cmd.Parameters.AddWithValue("@pi_name", pi_name); cmd.Parameters.AddWithValue("@pi_description", pi_description); cmd.Parameters.AddWithValue("@pi_price", pi_price); cmd.Parameters.AddWithValue("@pi_recurring", pi_recurring); 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("ProductInfo_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; } /****************************************************************************************************/ }