I know this is a busy question and there can be many, many answers, but ..... I am creating a small application that will be used by me and several other friends at the moment, and if he likes it more, I will distribute it to them. This is a simple customer tracking app for people with disabilities. It will track customers, payments, payment history, schedule, files (photos, emails, etc.). And, perhaps, a little more, but overall a very simple program. Oh yes, using SQLExpress as the source. My question is this: what is the best approach to designing the objects needed for this application? I read articles about data access layers and business objects, but I never created them from scratch. I thought about such objects as โClientโ, โPaymentโ, etc., And, of course, all the properties that come with them, but when it comes to changing the database, you should add methods to add, update, delete and etc. be in DAL with an object just passing the name of the stored procedure?
I know that there is a lot of information that is probably missing, but hopefully you can get a gist (sp?) Of what I'm trying to do.
** to reply to some of the messages:
I agree that the object will be split into dal, but I will need to learn more about how to create it this way ... again, new to OO programming, so I cannot fully see the whole picture.
Here's the DAL that a friend made and allowed me to use it:
namespace DataAccess{ public class SQLDataBase { public SQLDataBase(); public SQLDataBase(string EncodedConnectionString); public SQLDataBase(string EncodedConnectionString, int ConnectionTimeout); public string ConnectionString { get; set; } public int ConnectionTimeout { get; set; } public string EncodedConnectionString { get; } public void RunSpGetScaler(string spName, SqlParameter[] parms, ref DateTime ReturnValue); public void RunSpGetScaler(string spName, SqlParameter[] parms, ref decimal ReturnValue); public void RunSpGetScaler(string spName, SqlParameter[] parms, ref int ReturnValue); public void RunSpGetScaler(string spName, SqlParameter[] parms, ref string ReturnValue); public DataSet RunSpReturnDS(string DatasetName, string spName); public DataSet RunSpReturnDS(string DatasetName, string spName, SqlParameter[] parms); public int RunSpReturnRecordCount(string spName); public int RunSpReturnRecordCount(string spName, SqlParameter[] parms); public string RunSpReturnString(string spName, SqlParameter[] parms, string returnParm); public SqlConnection RunSqlConnection(); }
}
pretty simple ... the only problem I am facing is when I create any objects to use it, I have to write methods for every call I make in the database .... like this:
//Declarations - which I don't thinkk should be in the object itself private DataAccess.SQLDataBase oDatabase = null; private string sEncodedConnectionString = app.Default.EncodedDBString; private int iConnectionTimeout = 15; public DataSet GetClientInformation(int iClinetID, string sClientName) { oDatabase = new SQLDataBase( sEncodedConnectionString, iConnectionTimeout); string spName = "GetClientInformation"; string dsName = "GetClientInformation"; try { SqlParameter[] Params = new SqlParameter[2]; Params[0] = new SqlParameter("@ClientID", iClientID); Params[1] = new SqlParameter("@ClientName", sClientName); DataSet ds = oDatabase.RunSpReturnDS(dsName, spName, Params); return ds; } catch (Exception e) { throw (e); } }
So, for my client object, I have this and several other methods for adding, modifying, or selecting data for the โclientโ. Logically, this does not make sense to me, because it seems that I can not use it without having to have several other dependencies with it.