Tuesday, April 3, 2012

Simple Database Wrapper Class

using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Configuration;
///
/// Summary description for db
///
public class db
{
public db()
{
//
// TODO: Add constructor logic here
//
}
string _conn = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
public DataSet GetDsBySpArr(String spName, string[] key, object[] value)
{
DbConnection connection = new SqlConnection(_conn);
SqlCommand cmd = (SqlCommand)connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName.ToString();
DbParameter parm;
for (int i = 0; i < key.Length; i++)
{
// db.AddInParameter(dbCommand, (string)key.GetValue(i), GetDBType(value1.GetValue(i).GetType().Name), value1.GetValue(i));
parm = cmd.CreateParameter();
parm.ParameterName = (string)key.GetValue(i);
parm.Value = value.GetValue(i);
cmd.Parameters.Add(parm);
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet pubsDataSet = new DataSet("Pubs");
da.Fill(pubsDataSet);
connection.Close();
return pubsDataSet;
}
public DataSet GetDsBySp(String spName)
{
 
DbConnection connection = new SqlConnection(_conn);
SqlCommand cmd = (SqlCommand)connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName.ToString();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet pubsDataSet = new DataSet("Pubs");
da.Fill(pubsDataSet, "publishers");
connection.Close();
return pubsDataSet;
}
public void ExecuteSp(String sp_name, string[] key, object[] value)
{
DbConnection connection = new SqlConnection(_conn);
connection.Open();
SqlCommand cmd = (SqlCommand)connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
if (sp_name != null) cmd.CommandText = sp_name;
DbParameter parm;
for (int i = 0; i <= key.Length - 1; i++)
{
parm = cmd.CreateParameter();
parm.ParameterName = (string)key.GetValue(i);
parm.Value = value.GetValue(i);
cmd.Parameters.Add(parm);
}
cmd.ExecuteNonQuery();
connection.Close();
}
public object ExecuteScaler(String spName, string[] key, object[] value)
{
DbConnection connection = new SqlConnection(_conn);
connection.Open();
SqlCommand cmd = (SqlCommand)connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
if (spName != null) cmd.CommandText = spName;
DbParameter parm;
for (int i = 0; i <= key.Length - 1; i++)
{
parm = cmd.CreateParameter();
parm.ParameterName = (string)key.GetValue(i);
parm.Value = value.GetValue(i);
cmd.Parameters.Add(parm);
}
object scalerresult = cmd.ExecuteScalar();
connection.Close();
return scalerresult;
}
 
 
 
}

Wednesday, April 27, 2011

Following are some guidelines

Guidelines for Software Architect



1. Do not drive the architecture from the structure of the use cases. Instead, use domain experts and object modeling to identify the key business abstractions.
2. Identifying Software Components i.e. distribution, concurrency, layering, cohesion, and coupling.
3. Identify and manage non-functional requirements.
4. Take owner of the proposed Architecture and guide the team members during the implementation.
5. Undertake the technical leadership to ensure everything is taken care of and that the team is being steered in the right direction on a continuous basis.
6. Ensure that all business processes are coded inside business tier.
7. Update class diagram for every project even for a small change. Changes should be highlighted in the diagram
8. Activity , sequence and collaboration diagram will be created if approved by Management
9. All the architectural, design and specification changes to the system will be made by the approval of Software Architect.
10. ERD will be created or updated if a new table or data field changes
11. Best practices and pattern should be used for both .net and sql
12. Perform code review on weekly basis.
13. Proper Naming convention should be used for all .net and SQL related code
14. All classes, method and functions should get approved by Software Architect