Introduction
Included in the source files are four useful classes for everyone to use. They are as follows:
ConfigObj class -- class to manage configuration details for the application.
MsSql class -- a class dedicated to handle MS-SQL connections. It currently allows both simple SQL and transactions.
Errorlogger class -- a class dedicated to do errorlogging.
OleDB class -- a class dedicated to handle OleDB connections.
An example to illustrate the use of these classes are also included.
Details
I will now explain what each class does in details.
ConfigObj class
This class is a manager for configuration details. It allows both program updating of the values of the keys and auto-updating of the keys stored in the configuration files. An example of its use is as follows:
configobj.configobj config=new configobj.configobj();
config.addkey("config1"); config.addkey("config2");
In the app.config or web.config, the setting will be as such:
<configuration>
<appSettings>
<add key="config1" value="value1"/>
<add key="config2" value="value2"/>
</appSettings>
</configuration>
To use it, simply use the getkey function to return the value of the key.
Note that, when adding key, the name of the key must be the same as what it is in the configuration file.
The neat part of this class is that, if you are programming big applications with more than two programmers, using this class allows cleaner and neater codes for maintenance and ease of use. Enhancements are currently being done on this class to allow greater flexibility and usability.
MsSql class
This class is basically a class dedicated to access MS-SQL databases. It further enhances the current Microsoft MS SQL methods by adding in error capturing. An example of its use is as such:
config.addkey("mssql");
mssql.Sql sql=new Sql();sql.Constr=config.getkey("mssql"); sql.ExecuteNonQuery("Insert into the table " +
"(field1test,field2test) values ("+"'1','2')");
mssql.sqltransobj transsql=new sqltransobj(); transsql.Constr=config.getkey("mssql"); transsql.begin();
transsql.addtransaction("Insert into the table " +
"(field1test,field2test) values ("+"'1','2')");
transsql.commit();
transsql.close();
The simple SQL class caters for error capturing and graceful exiting when it encounters an error, either in the connection or the SQL being sent. The transaction class, built on top of it, also has same functionality.
Enhancement is currently being done to include stored procedures handling.
Errorlogger Class
A class dedicated to do errorlogging. Nothing special though. All error messages thrown in are formatted and stored in a text file for viewing. An example of its use is as follows:
try
{
..do something
}
catch (Exception e)
{
ErrorLog.writetolog(e.Message+"from where ",e.StackTrace);
}
Although simple, it proves to be a valuable class for any decent developers who require error handling. This class is used throughout the three other classes that is included also.
Enhancements is done on this class to make it send emails to a set of predefined users on encountering an error.
OleDB Class
This class is a further enhancement of the Microsoft OleDB class, similar concept to the MS-SQL class. What it provides basically are the four most used methods with error handling built into it.
The plus point of this class is that, any database connections required to use this class need only to supply the necessary parameters to make a new class that is easy to use. The source code given illustrates this clearly with the foxpro class built on top of it. And to use this class, developers simply has to do this:
configobj.configobj config=new configobj.configobj();
config.addkey("thetable");
config.addkey("initpath");
OleDB.VFPDB testconnect=new VFPDB();
testconnect.Source=config.getkey("thetable");
testconnect.executeNonQuery("insert into thetable " +
"(field1test,field2test) values ("+"'1','2')");
Further enhancements on this class are also in progress.
Looking at the big picture
You might have realised after looking at the codes that, there are actually two base classes (errorlogger and configobj) with two other classes (mssql and oledb) built with these base classes as dependencies. The two base classes can however still make use of the other two classes without much difficulty, say like if the error messages are to be kept in the database, the class can be modified to include the mssql class to do so easily. That is the actual intention when building the nature of these classes, that is, each class is dedicated to doing only one task, and that if it requires any sub-services to enhance its functionality, it calls another class for service with messages only, and not by manipulating that object. Personally, I believe by following this concept of only using messages to communicate objects with objects, it greatly reduces enhancements and maintenance efforts and increases flexibility.
Final Word
These codes are not totally bug-free, please feel free to email me the bugs that are found. Also, I might also have explained some concepts wrongly. Last but not least, all suggestions are welcome.