|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using ConnLibrary;
namespace ProjectBusiness
{
public class Project
{
public List<Employee> Employees { get; set; }
public string Name { get; set; }
private object updateStatusLock = new object();
/// <summary>
/// Updates the status of Project
/// </summary>
/// <exception cref="System.Data.SqlClient.SqlException">System.Data.SqlClient.SqlException</exception>
/// <exception cref="System.InvalidOperationException">System.InvalidOperationException</exception>
public void UpdateStatus()
{
lock (updateStatusLock)
{
DBConnectionManager connManager = new DBConnectionManager();
DbTransaction transaction = null;
try
{
connManager.Connection.Open();
//It is Project objects responsibility to commit multiple Database updates in one transaction.
transaction = connManager.Connection.BeginTransaction();
//some checks for project status..
string cmdString = "INSERT INTO PROJECTS VALUES('" + Name + "','Hello')";
connManager.Connection.ExecuteScalar(cmdString, transaction);
if (Employees != null)
foreach (Employee employee in Employees)
employee.UpdateStatus(this, transaction,connManager);
transaction.Commit();
transaction = null;
}
catch (System.InvalidOperationException invalidOperatioExcpetion)
{
throw;
}
catch (System.Data.SqlClient.SqlException sqlException)
{
throw;
}
catch
{
throw;
}
finally
{
if (connManager.Connection.IsOpen())
{
connManager.Connection.Close();
}
if (transaction != null)
{
transaction.Rollback();
}
transaction = null;
connManager = null;
}
}
}
/// <summary>
/// Updates the status of Project
/// </summary>
/// <exception cref="System.Data.SqlClient.SqlException">System.Data.SqlClient.SqlException</exception>
/// <exception cref="System.InvalidOperationException">System.InvalidOperationException</exception>
public void UpdateStatusSingleton()
{
lock (updateStatusLock)
{
DbTransaction transaction = null;
try
{
SharedConnectionManager.Connection.Open();
//It is Project objects responsibility to commit multiple Database updates in one transaction.
transaction = SharedConnectionManager.Connection.BeginTransaction();
//some checks for project status..
string cmdString = "INSERT INTO PROJECTS VALUES('" + Name + "','Hello')";
SharedConnectionManager.Connection.ExecuteScalar(cmdString, transaction);
if (Employees != null)
foreach (Employee employee in Employees)
employee.UpdateStatus(this, transaction);
transaction.Commit();
transaction = null;
SharedConnectionManager.Connection.Close();
}
catch (System.InvalidOperationException invalidOperatioExcpetion)
{
throw;
}
catch (System.Data.SqlClient.SqlException sqlException)
{
throw;
}
catch
{
throw;
}
finally
{
if (SharedConnectionManager.Connection.IsOpen())
{
SharedConnectionManager.Connection.Close();
}
if (transaction != null)
{
transaction.Rollback();
}
transaction = null;
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.