Friday, January 22, 2010

BLL_Affiliate.cs

using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Rupiz.SqlDatabaseHelper;

namespace Rupiz.AffiliateNetwork
{
public class BLL_AffiliateNetworkManagement
{

#region "Constructor"

private String _conString;
public BLL_AffiliateNetworkManagement()
{
try
{
if (ConfigurationManager.ConnectionStrings["strConnectionString"] != null)
{
_conString = ConfigurationManager.ConnectionStrings["strConnectionString"].ConnectionString;
}
else
{
throw new ApplicationException("Sorry, connection to database could not made");
}
}
catch
{
throw;
}
}

#endregion

#region "PROPERTIES"

private int? _affNetId = null;
public int? AffNetId
{
get { return _affNetId; }
set { _affNetId = value; }
}

private string _affNetName;
public string AffNetName
{
get { return _affNetName; }
set { _affNetName = value; }
}

private string _affNetUrl;
public string AffNetUrl
{
get { return _affNetUrl; }
set { _affNetUrl = value; }
}

private string _affNetDescription;
public string AffNetDescription
{
get { return _affNetDescription; }
set { _affNetDescription = value; }
}

private string _paymentMode;
public string PaymentMode
{
get { return _paymentMode; }
set { _paymentMode = value; }
}

private string _paymentGrace;
public string PaymentGrace
{
get { return _paymentGrace; }
set { _paymentGrace = value; }
}

private int? _status = null;
public int? Status
{
get { return _status; }
set { _status = value; }
}

private int? _userid = null;
public int? UserID
{
get { return _userid; }
set { _userid = value; }
}

#endregion

#region "FUNCTIONS"

public DataTable GetAllAffiliate()
{
try
{
DataSet ds = SqlHelper.ExecuteDataset(_conString, CommandType.StoredProcedure, "usp_GetAllAffiliate"); // Get Affiliates from database
if (ds != null)
{
DataTable dt = ds.Tables[0].Copy();
ds.Dispose();
return dt;
}
else
{
return (DataTable)null;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

public void GetAffiliateById()
{
try
{
SqlParameter pAffId = SqlHelper.CreateParameter("@AffiliateId", AffNetId);
SqlParameter[] allParams = { pAffId };
DataSet ds = SqlHelper.ExecuteDataset(_conString, "usp_GetAffiliateById", pAffId); // Get Affiliates from database
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
DataRow dr = ds.Tables[0].Rows[0];
if (dr != null)
{
AffNetDescription = String.Empty;
if (dr["AffDescription"].ToString() != null)
{
AffNetDescription = dr["AffDescription"].ToString();
}
AffNetName = String.Empty;
if (dr["AffNetworkName"].ToString() != null)
{
AffNetName = dr["AffNetworkName"].ToString();
}
AffNetUrl = String.Empty;
if (dr["AffiliateUrl"].ToString() != null)
{
AffNetUrl = dr["AffiliateUrl"].ToString();
}
PaymentMode = String.Empty;
if (dr["PaymentMode"].ToString() != null)
{
PaymentMode = dr["PaymentMode"].ToString();
}
PaymentGrace = String.Empty;
if (dr["PaymentDate"].ToString() != null)
{
PaymentGrace = dr["PaymentDate"].ToString();
}
if (dr["AffiliateStatus"].ToString() != null)
{
Status = Convert.ToInt32(dr["AffiliateStatus"].ToString());
}
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

public int AddUpdAffiliate()
{
try
{
SqlParameter pAffiliateId = SqlHelper.CreateParameter("@AffiliateId", DBNull.Value);
if (AffNetId.HasValue)
{
pAffiliateId.Value = AffNetId.Value;
}
SqlParameter pNetworkName = SqlHelper.CreateParameter("@AffNetworkName", DBNull.Value);
if (AffNetName != string.Empty)
{
pNetworkName.Value = AffNetName;
}
SqlParameter pAffNetUrl = SqlHelper.CreateParameter("@AffiliateUrl", DBNull.Value);
if (AffNetUrl != string.Empty)
{
pAffNetUrl.Value = AffNetUrl;
}
SqlParameter pAffNetDescription = SqlHelper.CreateParameter("@AffDescription", DBNull.Value);
if (AffNetDescription != string.Empty)
{
pAffNetDescription.Value = AffNetDescription;
}
SqlParameter pPaymentMode = SqlHelper.CreateParameter("@PaymentMode", DBNull.Value);
if (PaymentMode != string.Empty)
{
pPaymentMode.Value = PaymentMode;
}
SqlParameter pPaymentGrace = SqlHelper.CreateParameter("@PaymentDate", DBNull.Value);
if (PaymentGrace != string.Empty)
{
pPaymentGrace.Value = PaymentGrace;
}
SqlParameter pModifiedBy = SqlHelper.CreateParameter("@ModifiedBy", DBNull.Value);
if (UserID.HasValue)
{
pModifiedBy.Value = UserID.HasValue;
}
SqlParameter pErr = SqlHelper.CreateParameter("@err", -1, ParameterDirection.Output);
SqlParameter pStatus = SqlHelper.CreateParameter("@AffiliateStatus", DBNull.Value);
if (Status.HasValue)
{
pStatus.Value = Status.Value;
}
// create array of parameters
SqlParameter[] allParams = { pAffiliateId, pNetworkName, pAffNetUrl, pAffNetDescription, pPaymentMode, pPaymentGrace, pModifiedBy, pStatus, pErr };

// store data into the database
SqlHelper.ExecuteNonQuery(_conString, CommandType.StoredProcedure, "usp_AddUpdAffiliate", allParams);

// return the error number (0,1)
int result = -1;
if (pErr.Value != null)
{
result = (int)pErr.Value;
}
return result;

}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

}

public DataTable GetAffiliateNetworkByStatus(int Status)
{
try
{
SqlParameter statusAff = SqlHelper.CreateParameter("@AffiliateStatus", Status);
SqlParameter[] allParams = { statusAff };
// store data into the database
DataSet ds = SqlHelper.ExecuteDataset(_conString, CommandType.StoredProcedure, "usp_GetAllAffiliateByStatus", allParams);
// return the error number (0,1)
if (ds != null)
{
DataTable dt = ds.Tables[0].Copy();
ds.Dispose();
return dt;
}
else
{
return (DataTable)null;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

//public int AddAffiliateNetwork()
//{
// try
// {
// // create parameters
// SqlParameter affNetworkName = SqlHelper.CreateParameter("@AffNetworkName", AffNetName);
// SqlParameter affiliateUrl = SqlHelper.CreateParameter("@AffiliateUrl", AffNetUrl);
// SqlParameter affDescription = SqlHelper.CreateParameter("@AffDescription", AffNetDescription);
// SqlParameter paymentMode = SqlHelper.CreateParameter("@PaymentMode", PaymentMode);
// SqlParameter paymentDate = SqlHelper.CreateParameter("@PaymentDate", PaymentGrace);
// SqlParameter modifiedBy = SqlHelper.CreateParameter("@ModifiedBy", UserID);
// SqlParameter pErr = SqlHelper.CreateParameter("@err", -1, ParameterDirection.Output);
// // create array of parameters
// SqlParameter[] allParams = { affNetworkName, affiliateUrl, affDescription, paymentMode, paymentDate, modifiedBy, pErr };

// // store data into the database
// SqlHelper.ExecuteNonQuery(_conString, CommandType.StoredProcedure, "usp_AddNewAffiliate", allParams);

// // return the error number (0,1)
// int result = -1;
// if (pErr.Value != null)
// {
// result = (int)pErr.Value;
// }
// return result;

// }
// catch (Exception ex)
// {
// throw new Exception(ex.Message);
// }

//}

//public int UpdateAffiliateNetworkStatus()
//{
// try
// {
// // create parameters
// SqlParameter affNetworkId = SqlHelper.CreateParameter("@AffiliateId", AffNetId);
// SqlParameter affStatus = SqlHelper.CreateParameter("@AffiliateStatus", Status);
// SqlParameter modifiedBy = SqlHelper.CreateParameter("@ModifiedBy", UserID);
// SqlParameter pErr = SqlHelper.CreateParameter("@err", -1, ParameterDirection.Output);
// // create array of parameters
// SqlParameter[] allParams = { affNetworkId, affStatus, modifiedBy, pErr };
// // store data into the database
// SqlHelper.ExecuteNonQuery(_conString, CommandType.StoredProcedure, "usp_UpdateAffiliate", allParams);
// // return the error number (0,1)
// int result = -1;
// if (pErr.Value != null)
// {
// result = (int)pErr.Value;
// }
// return result;

// }
// catch (Exception ex)
// {
// throw new Exception(ex.Message);
// }

//}

//public int UpdateAffiliateNetwork()
//{
// try
// {
// // create parameters
// SqlParameter affNetworkId = SqlHelper.CreateParameter("@AffiliateId", AffNetId);
// SqlParameter affiliateUrl = SqlHelper.CreateParameter("@AffiliateUrl", AffNetUrl);
// SqlParameter affDescription = SqlHelper.CreateParameter("@AffDescription", AffNetDescription);
// SqlParameter paymentMode = SqlHelper.CreateParameter("@PaymentMode", PaymentMode);
// SqlParameter paymentDate = SqlHelper.CreateParameter("@PaymentDate", PaymentGrace);
// SqlParameter modifiedBy = SqlHelper.CreateParameter("@ModifiedBy", UserID);
// SqlParameter statusAff = SqlHelper.CreateParameter("@AffiliateStatus", Status);
// SqlParameter pErr = SqlHelper.CreateParameter("@err", -1, ParameterDirection.Output);

// // create array of parameters
// SqlParameter[] allParams = { affNetworkId, affiliateUrl, affDescription, paymentMode, paymentDate, modifiedBy, statusAff, pErr };

// // store data into the database
// SqlHelper.ExecuteNonQuery(_conString, CommandType.StoredProcedure, "usp_UpdateAffiliate", allParams);

// // return the error number (0,1)
// int result = -1;
// if (pErr.Value != null)
// {
// result = (int)pErr.Value;
// }
// return result;
// }
// catch (Exception ex)
// {
// throw new Exception(ex.Message);
// }
//}


#endregion
}
}

No comments:

Post a Comment