Inland Empire .NET User's Group Forums
 Home        Members    Calendar    Who's On

Welcome Guest ( Login | Register )
      



c# abstract classesExpand / Collapse
Message
Posted 10/5/2007 9:01:54 AMPost #44
 

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie
I am in the process of trying to set up 2 classes for developers to derive from. One is for technical documents, and one is for non technical documents. I set up an abstract base class, and some abstract methods. In the base class methods, I set up the methods to take a parameter of cbb_doc. I was hoping that when the developer derived from the base class, they would be able to override the base method, and write thier own version for updating a technical document, as well as thier own version of how to update a non-technical document. Unfortuanlty, during testing this thing, when I overrode the abstract base method, at design time, I was only able to set up the base cbb_doc as a parameter, and not the tech_cbb_doc.

This is not a good thing, because even though I can pass in a tech_cbb_doc, at design time, I only have access to the properties from the base file.

The overall goal is to require the developer to name his update, inactivate, and insert methods for documents in exactly the same way. I though about using interfaces, but I want to reserve the right to add some code in there myself for latter, just in case I want to do some tracking, or some updating of a data warehouse when the modification happens. I would not be able to do that if I used an interface, becasue as far as I know, you can't write any code when you declare an interface, you can only declare the method.

Any suggestions would be greatly appreciated. I have attached some sample code.

///////////////////////////abstract class////////////////////////////////////////

using System;

using System.Data;

using System.Configuration;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Xml.Linq;

using System.Web.Configuration;

namespace intranet_main

{

/// <summary>

/// Default class for a CBB Document

/// </summary>

public abstract class cbb_doc

{

#region private_variables

private int _doc_id;

private string _doc_creator;

private string _doc_descrip;

private string _doc_how_to;

private int _mn_cat_id_num;

private string _doc_title;

private bool _doc_restrict;

private bool _doc_publish;

private DateTime _doc_create_dte;

private DateTime _doc_lst_updte_dte;

#endregion

#region Public_properties

/// <summary>

/// When was this document last updated

/// </summary>

public DateTime Doc_lst_updte_dte

{

get { return _doc_lst_updte_dte; }

set

{

if (value == null)

{

_doc_lst_updte_dte = DateTime.Today;

}

else

{

_doc_lst_updte_dte = value;

}

}

}

/// <summary>

/// What is the Database Generated ID number of this document

/// </summary>

public int Doc_id

{

get { return _doc_id; }

set { _doc_id = value; }

}

/// <summary>

/// Who is the creator of this document

/// </summary>

public string Doc_creator

{

get { return _doc_creator; }

set { _doc_creator = value.Trim().ToUpper(); }

}

/// <summary>

/// Describe the document

/// </summary>

public string Doc_descrip

{

get { return _doc_descrip; }

set { _doc_descrip = value; }

}

/// <summary>

/// Give a step by step explanation of what the document is supposed to be explaining to you how to do.

/// </summary>

public string Doc_how_to

{

get { return _doc_how_to; }

set { _doc_how_to = value; }

}

/// <summary>

/// What is the category ID number of this document from the category table.

/// </summary>

public int mn_cat_id_num

{

get { return _mn_cat_id_num; }

set { _mn_cat_id_num = value; }

}

/// <summary>

/// what is the title of this document

/// </summary>

public string Doc_title

{

get { return _doc_title; }

set { _doc_title = value.ToUpper().Trim(); }

}

/// <summary>

/// Should this document be Management Eyes only

/// </summary>

public bool Doc_restrict

{

get { return _doc_restrict; }

set { _doc_restrict = value; }

}

/// <summary>

/// What is the date this document was created

/// </summary>

public DateTime Doc_create_dte

{

get { return _doc_create_dte; }

set {

if (value == null)

{

_doc_create_dte = DateTime.Today;

}

else

{

_doc_create_dte = value;

}

}

}

/// <summary>

/// Is this Document ready to be Published

/// </summary>

public bool Publish

{

get { return _doc_publish; }

set { _doc_publish = value; }

}

#endregion

/// <summary>

/// default Constructor

/// </summary>

public cbb_doc()

{

//set all the variables to default values

this._doc_create_dte = DateTime.Today;

this._doc_creator = "System";

this._doc_descrip = "No Description Has Been Provided for this document";

this._doc_how_to = "No Step by Step Instructions have been provided for this document";

this._doc_lst_updte_dte = DateTime.Today;

this._doc_restrict = false;

this._doc_publish = false;

this._doc_title = "No Title has been provided for this Document";

this._mn_cat_id_num = 1;

}

/// <summary>

/// Alternate Constructor for instantion from a derived class

/// </summary>

/// <param name="create_date">What is the date this document was originally created</param>

/// <param name="Creator">Who Created This Document</param>

/// <param name="Descrip">Provide a Brief Description of the document</param>

/// <param name="how_to">Provide Step by Step instructions on what this document is supposed to explain to you how to do</param>

/// <param name="Lst_updte">When was this document last updated</param>

/// <param name="restricted">Should this document be restricted to Management only</param>

/// <param name="pubish">Is this document ready to be published for everyone to see, or is it for IS department and the write only</param>

/// <param name="title">What is the title of this document</param>

/// <param name="category_id">What is the ID number of the category of this document</param>

public cbb_doc(DateTime create_date, string Creator, string Descrip, string how_to, DateTime Lst_updte, bool restricted, bool pubish, string title, int category_id)

{

this.Doc_create_dte = create_date;

this.Doc_creator = Creator;

this.Doc_descrip = Descrip;

this.Doc_how_to = how_to;

this.Doc_lst_updte_dte = Lst_updte;

this.Doc_restrict = restricted;

this.Publish = pubish;

this.Doc_title = title;

this.mn_cat_id_num = category_id;

}

}

/// <summary>

/// this class is used to establish connectivity with the database and get a list of required methods.

/// </summary>

public abstract class cbb_doc_connectivity

{

private string conn = WebConfigurationManager.ConnectionStrings["cbb_conn"].ConnectionString;

/// <summary>

/// Get the connection string from the config file.

/// </summary>

public string Conn

{

get { return conn; }

}

public cbb_doc_connectivity()

{

}

/// <summary>

/// Alternative connection string can be passed in

/// </summary>

/// <param name="connection_string">What is the alternative connection string you want to use</param>

public cbb_doc_connectivity(string connection_string)

{

this.conn = connection_string;

}

/// <summary>

/// Implement a method that will retrieve 1 document from the db based on the ID number

/// </summary>

/// <param name="doc_tech_id">What is the ID number of the document that you want to retrieve</param>

/// <returns></returns>

public abstract System.Data.DataTable doc_get_id(int doc_tech_id);

/// <summary>

/// Implement a method for retrieveing all of the documents for a specific type using the connection string from this object.

/// </summary>

/// <param name="doc_type">What document type are you looking for. Technical or non technical</param>

/// <returns></returns>

public abstract System.Data.DataTable doc_getall(int doc_type);

public abstract Datatable doc_update(cbb_doc);

/////////////////////////////////////abstract class ///////////////////////////////////////////////

///////////////////////////derived class//////////////////////////////////////////////////////////

using System;

using System.Data;

using System.Configuration;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Xml.Linq;

using System.Data.SqlClient;

using System.Collections.Generic;

namespace intranet_main

{

/// <summary>

/// This is the class for a technical document detail

/// </summary>

public class doc_tech_det : cbb_doc

{

# region Private variables

private int _uzr_id_num = 1;

private string _doc_tech_rel_req = "No Related Requirements Provided at this time";

private string _doc_tech_gl_n_cntxt = "No goal in context Provided at this time";

private string _doc_tech_pre_con = "No Pre-Existing Conditions Provided at this time";

private string _doc_tech_suc_end_con = "No Succesful end condition has been identified at this time.";

private string _doc_tech_fail_end_con = "No failed end condition has been identified at this time";

private string _doc_tech_prime_act = "No Primary Actors identified at this time";

private string _doc_tech_sec_act = "No Secondary Actors Identified at this time";

#endregion

#region Properties for private variables in this class

/// <summary>

/// What is the ID number of the User who is making this entry??

/// </summary>

public int uzr_id_num

{

get { return _uzr_id_num; }

set

{

if (value <= 0)

{

_uzr_id_num = 1;

}

else

{

_uzr_id_num = value;

}

}

}

/// <summary>

/// What are the related requirments for the use of this procedure.

/// </summary>

public string doc_tech_rel_req

{

get { return _doc_tech_rel_req; }

set { _doc_tech_rel_req = value; }

}

/// <summary>

/// What is the goal of the procedure defined within the context of the document

/// </summary>

public string doc_tech_gl_n_cntxt

{

get { return _doc_tech_gl_n_cntxt; }

set { _doc_tech_gl_n_cntxt = value; }

}

/// <summary>

/// What pre-Existing conditions need to be in place before this document can be applied.

/// </summary>

public string doc_tech_pre_con

{

get { return _doc_tech_pre_con; }

set { _doc_tech_pre_con = value; }

}

/// <summary>

/// How can you tell if this procedure was succesful???

/// </summary>

public string doc_tech_suc_end_con

{

get { return _doc_tech_suc_end_con; }

set { _doc_tech_suc_end_con = value; }

}

/// <summary>

/// how can you tell if this procedure has failed???

/// </summary>

public string doc_tech_fail_end_con

{

get { return _doc_tech_fail_end_con; }

set { _doc_tech_fail_end_con = value; }

}

/// <summary>

/// Who will be the primary users of this procedure

/// </summary>

public string doc_tech_prime_act

{

get { return _doc_tech_prime_act; }

set { _doc_tech_prime_act = value; }

}

/// <summary>

/// Who will be the secondary users of this procedure

/// </summary>

public string doc_tech_sec_act

{

get { return _doc_tech_sec_act; }

set { _doc_tech_sec_act = value; }

}

#endregion

#region Properties from base class

//unfortunatly in order for this class to be usable by the object data source, the public fields of this class have to be the same name as the fields in the table. For that reason, I am re-naming some of the properties from the base class

/// <summary>

/// Last day this was updated

/// </summary>

public DateTime doc_tech_dte

{

get { return Doc_lst_updte_dte; }

set { Doc_lst_updte_dte = value; }

}

/// <summary>

/// The ID number of this document

/// </summary>

public int doc_tech_id

{

get { return Doc_id; }

set { Doc_id = value; }

}

/// <summary>

/// Who is the author of this document??

/// </summary>

public string doc_tech_creator

{

get { return Doc_creator; }

set { Doc_creator = value; }

}

/// <summary>

/// Provide a brief summary of what this document is about.

/// </summary>

public string doc_tech_descrip

{

get { return Doc_descrip; }

set { Doc_descrip = value; }

}

/// <summary>

/// What is the Main Flow of this Document

/// </summary>

public string doc_tech_mn_flow

{

get { return Doc_how_to; }

set { Doc_how_to = value; }

}

/// <summary>

/// Should this Technical document be Published or is it for IS/Author eyes only??

/// </summary>

public bool doc_tech_publish

{

get { return this.Publish; }

set { this.Publish = value; }

}

/// <summary>

/// What is the Title of this Document

/// </summary>

public string doc_tech_title

{

get { return this.Doc_title; }

set { Doc_title = value; }

}

/// <summary>

/// Should this document be restricted For Managers eyes only

/// </summary>

public bool doc_tech_restrict

{

get { return this.Doc_restrict; }

set { Doc_restrict = value; }

}

/// <summary>

/// When was this Technical document created

/// </summary>

public DateTime doc_tech_create_dte

{

get { return this.Doc_create_dte; }

set { this.Doc_create_dte = value; }

}

#endregion

/// <summary>

/// Default Constructor, only used by object data source

/// </summary>

public doc_tech_det()

{

//nothing to be done, everything is set to defaults in the base, as well as in this derived class

}

/// <summary>

/// Instantiate your object by setting these variables explicitly

/// </summary>

/// <param name="createdate"> What is the original create date of this document</param>

/// <param name="creator">Who is the author of this document</param>

/// <param name="descrip">Provide a brief description for this document</param>

/// <param name="stepby">Give a detailed step by step of how to perform the procedure</param>

/// <param name="lstupdate">when was this document last updated</param>

/// <param name="restricted">Shoudl this document be restricted to Managment eyes only</param>

/// <param name="publish">Should this document be published to the general public, or for IS/Author eyes only</param>

/// <param name="doctitle">What is the title of this document</param>

/// <param name="catid"> What is the category of this document</param>

public doc_tech_det(DateTime createdate, string creator, string descrip, string stepby, DateTime lstupdate, bool restricted, bool publish, string doctitle, int catid) :

base(createdate, creator, descrip, stepby, lstupdate, restricted, publish, doctitle, catid)

{

}

}

public class doc_tech_dac : cbb_doc_connectivity

{

public doc_tech_dac()

{

}

public int inactivate_document(doc_tech_det document)

{

int affected_records;

SqlConnection conn = new SqlConnection(this.Conn);

SqlCommand cmd = new SqlCommand("doc_tech_del", conn);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@doc_tech_id", SqlDbType.Int));

cmd.Parameters["@doc_tech_id"].Value = document.doc_tech_id;

//running

try

{

conn.Open();

affected_records= cmd.ExecuteNonQuery();

return affected_records;

}

catch(SqlException ex)

{

throw new ApplicationException(ex.Message.ToString());

}

finally

{

conn.Close();

}

}

public bool update_document(doc_tech_det document)

{

SqlConnection conn = new SqlConnection(this.Conn);

SqlCommand cmd = new SqlCommand("doc_tech_updte", conn);

cmd.CommandType = CommandType.StoredProcedure;

//adding all of the parameters I need to do the updates

cmd.Parameters.Add(new SqlParameter("@doc_tech_id", SqlDbType.Int));

cmd.Parameters["@doc_tech_id"].Value = document.doc_tech_id;

cmd.Parameters.Add(new SqlParameter("@doc_tech_creator", SqlDbType.Char, 30));

cmd.Parameters["@doc_tech_creator"].Value = document.doc_tech_creator;

cmd.Parameters.Add(new SqlParameter("@doc_tech_create_dte", SqlDbType.VarChar, 50));

cmd.Parameters["@doc_tech_create_dte"].Value = document.doc_tech_create_dte;

cmd.Parameters.Add(new SqlParameter("@uzr_id_num", SqlDbType.Int));

cmd.Parameters["@uzr_id_num"].Value = document.uzr_id_num;

cmd.Parameters.Add(new SqlParameter("@doc_tech_descrip", SqlDbType.NText));

cmd.Parameters["@doc_tech_descrip"].Value = document.doc_tech_descrip;

cmd.Parameters.Add(new SqlParameter("@doc_tech_rel_req", SqlDbType.NText));

cmd.Parameters["@doc_tech_rel_req"].Value = document.doc_tech_rel_req;

cmd.Parameters.Add(new SqlParameter("@doc_tech_gl_n_cntxt", SqlDbType.NText));

cmd.Parameters["@doc_tech_gl_n_cntxt"].Value = document.doc_tech_gl_n_cntxt;

cmd.Parameters.Add(new SqlParameter("@doc_tech_pre_con", SqlDbType.NText));

cmd.Parameters["@doc_tech_pre_con"].Value = document.doc_tech_pre_con;

cmd.Parameters.Add(new SqlParameter("@doc_tech_suc_end_con", SqlDbType.NText));

cmd.Parameters["@doc_tech_suc_end_con"].Value = document.doc_tech_suc_end_con;

cmd.Parameters.Add(new SqlParameter("@doc_tech_fail_end_con", SqlDbType.NText));

cmd.Parameters["@doc_tech_fail_end_con"].Value = document.doc_tech_fail_end_con;

cmd.Parameters.Add(new SqlParameter("@doc_tech_prime_act", SqlDbType.NText));

cmd.Parameters["@doc_tech_prime_act"].Value = document.doc_tech_prime_act;

cmd.Parameters.Add(new SqlParameter("@doc_tech_sec_act", SqlDbType.NText));

cmd.Parameters["@doc_tech_sec_act"].Value = document.doc_tech_sec_act;

cmd.Parameters.Add(new SqlParameter("@doc_tech_mn_flow", SqlDbType.NText));

cmd.Parameters["@doc_tech_mn_flow"].Value = document.doc_tech_mn_flow;

cmd.Parameters.Add(new SqlParameter("@doc_tech_publish", SqlDbType.Bit));

cmd.Parameters["@doc_tech_publish"].Value = document.doc_tech_publish;

cmd.Parameters.Add(new SqlParameter("@doc_tech_restrict", SqlDbType.Bit));

cmd.Parameters["@doc_tech_restrict"].Value = document.doc_tech_restrict;

cmd.Parameters.Add(new SqlParameter("@doc_tech_dte", SqlDbType.VarChar, 50));

cmd.Parameters["@doc_tech_dte"].Value = document.doc_tech_dte;

cmd.Parameters.Add(new SqlParameter("@mn_cat_id_num", SqlDbType.Int));

cmd.Parameters["@mn_cat_id_num"].Value = document.mn_cat_id_num;

cmd.Parameters.Add(new SqlParameter("@doc_tech_title", SqlDbType.NText));

cmd.Parameters["@doc_tech_title"].Value = document.doc_tech_title;

bool updated;

//running

try

{

conn.Open();

cmd.ExecuteNonQuery();

updated = true;

return updated;

}

catch (SqlException e)

{

string err = e.Message;

updated = false;

return updated;

}

finally

{

conn.Close();

}

}

public override DataTable doc_get_id(int doc_tech_id)

{

//need to coe this, this procedure takes a parameter

SqlConnection conn = new SqlConnection(this.Conn);

SqlCommand cmd = new SqlCommand("doc_tech_get_id", conn);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@doc_tech_id", SqlDbType.Int));

cmd.Parameters["@doc_tech_id"].Value = doc_tech_id;

SqlDataAdapter da = new SqlDataAdapter();

da.SelectCommand = cmd;

DataSet ds = new DataSet();

try

{

conn.Open();

da.Fill(ds, "doc_tech_item");

return ds.Tables["doc_tech_item"];

}

catch(System.Exception ex)

{

throw new ApplicationException(ex.Message.ToString());

}

}

public override DataTable doc_getall(int doc_type)

{

throw new NotImplementedException();

}

/// <summary>

/// This method updates all items in the db for a particular technical document

/// </summary>

public bool insrt_document(doc_tech_det document)

{

SqlConnection conn = new SqlConnection(this.Conn);

SqlCommand cmd = new SqlCommand("[doc_tech_insrt_record]", conn);

cmd.CommandType = CommandType.StoredProcedure;

//adding all of the parameters I need to do the updates

cmd.Parameters.Add(new SqlParameter("@doc_tech_id", SqlDbType.Int));

cmd.Parameters["@doc_tech_id"].Value = document.doc_tech_id;

cmd.Parameters.Add(new SqlParameter("@doc_tech_creator", SqlDbType.Char, 30));

cmd.Parameters["@doc_tech_creator"].Value = document.doc_tech_creator;

cmd.Parameters.Add(new SqlParameter("@doc_tech_create_dte", SqlDbType.VarChar, 50));

cmd.Parameters["@doc_tech_create_dte"].Value = document.doc_tech_create_dte;

cmd.Parameters.Add(new SqlParameter("@uzr_id_num", SqlDbType.Int));

cmd.Parameters["@uzr_id_num"].Value = document.uzr_id_num;

cmd.Parameters.Add(new SqlParameter("@doc_tech_descrip", SqlDbType.NText));

cmd.Parameters["@doc_tech_descrip"].Value = document.doc_tech_descrip;

cmd.Parameters.Add(new SqlParameter("@doc_tech_rel_req", SqlDbType.NText));

cmd.Parameters["@doc_tech_rel_req"].Value = document.doc_tech_rel_req;

cmd.Parameters.Add(new SqlParameter("@doc_tech_gl_n_cntxt", SqlDbType.NText));

cmd.Parameters["@doc_tech_gl_n_cntxt"].Value = document.doc_tech_gl_n_cntxt;

cmd.Parameters.Add(new SqlParameter("@doc_tech_pre_con", SqlDbType.NText));

cmd.Parameters["@doc_tech_pre_con"].Value = document.doc_tech_pre_con;

cmd.Parameters.Add(new SqlParameter("@doc_tech_suc_end_con", SqlDbType.NText));

cmd.Parameters["@doc_tech_suc_end_con"].Value = document.doc_tech_suc_end_con;

cmd.Parameters.Add(new SqlParameter("@doc_tech_fail_end_con", SqlDbType.NText));

cmd.Parameters["@doc_tech_fail_end_con"].Value = document.doc_tech_fail_end_con;

cmd.Parameters.Add(new SqlParameter("@doc_tech_prime_act", SqlDbType.NText));

cmd.Parameters["@doc_tech_prime_act"].Value = document.doc_tech_prime_act;

cmd.Parameters.Add(new SqlParameter("@doc_tech_sec_act", SqlDbType.NText));

cmd.Parameters["@doc_tech_sec_act"].Value = document.doc_tech_sec_act;

cmd.Parameters.Add(new SqlParameter("@doc_tech_mn_flow", SqlDbType.NText));

cmd.Parameters["@doc_tech_mn_flow"].Value = document.doc_tech_mn_flow;

cmd.Parameters.Add(new SqlParameter("@doc_tech_publish", SqlDbType.Bit));

cmd.Parameters["@doc_tech_publish"].Value = document.doc_tech_publish;

cmd.Parameters.Add(new SqlParameter("@doc_tech_restrict", SqlDbType.Bit));

cmd.Parameters["@doc_tech_restrict"].Value = document.doc_tech_restrict;

cmd.Parameters.Add(new SqlParameter("@doc_tech_dte", SqlDbType.VarChar, 50));

cmd.Parameters["@doc_tech_dte"].Value = document.doc_tech_dte;

cmd.Parameters.Add(new SqlParameter("@mn_cat_id_num", SqlDbType.Int));

cmd.Parameters["@mn_cat_id_num"].Value = document.mn_cat_id_num;

cmd.Parameters.Add(new SqlParameter("@doc_tech_title", SqlDbType.NText));

cmd.Parameters["@doc_tech_title"].Value = document.doc_tech_title;

bool updated;

//running

try

{

conn.Open();

cmd.ExecuteNonQuery();

updated = true;

return updated;

}

catch (Exception e)

{

string err = e.Message;

updated = false;

return updated;

}

finally

{

conn.Close();

}

}

/// <summary>

/// Get all of the technical documents in a particular category

/// This will return a datatable

/// </summary>

/// <param name="doc_tech_cat">What is the category number you are looking for</param>

/// <returns></returns>

public List<babystruct2> doc_tech_get_all_n_cat(int doc_tech_cat)

{

}

}

}

//////////////////////////////////Derived class ////////////////////////////////////////////////

Patrick Pearson

« Prev Topic | Next Topic »


PermissionsExpand / Collapse

All times are GMT -8:00, Time now is 9:36am

Powered By InstantForum.NET v4.1.3 © 2008
Execution: 0.702. 13 queries. Compression Enabled.