Monday, March 31, 2014

------>   Property  Class ---------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mohsin.Practices.PrivateLibrary.DataLib;
using System.Text;

namespace Mohsin.Practices.PrivateLibrary
{
  public  class Transaction_MasterProperty
    {
      public int Trans_Id { get; set; }
      public string Description { get; set; }
      public double Amount { get; set; }
      public int Category_Id { get; set; }
      public DateTime EntryDate { get; set; }
      public string  TransactionMode { get; set; }
      public int PurPose_Id { get; set; }
      public int PaymentMode_Id { get; set; }
      public int Currency_Id { get; set; }
      public int User_Id { get; set; }

     

     
    }
}
------------------------------------------------------------------------------
------>   Function  Class ---------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Mohsin.Practices.PrivateLibrary.DataLib;


namespace Mohsin.Practices.PrivateLibrary
{
   public  class Transaction_Master
    {
       #region << Variable Declared >>

       private DataAccess objDAL;

       #endregion

       #region << Stored Procedures Names >>

       private string PRCINS = "Transaction_MasterIns";
       private string PRCUPD = "Transaction_MasterUpd";
       private string PRCDEL = "Transaction_MasterDel";
       private string PRCGETBYID = "Transaction_MasterGetByID";
       private string PRCGETBYPARAM = "Transaction_MasterGetByParam";


       private string PRCGETMAINREPORT = "Transaction_MasterGetMainReport";

       #endregion

       #region << User Define Function >>

       public Int32 Insert(Transaction_MasterProperty  objProp)
       {
           try
           {
               objDAL = new DataAccess();

               objDAL.CreateCommand(PRCINS);

               objDAL.AddParameterToCommand("@Description", objProp.Description);
               objDAL.AddParameterToCommand("@Amount", objProp.Amount);
               objDAL.AddParameterToCommand("@Category_Id", objProp.Category_Id);
               objDAL.AddParameterToCommand("@EntryDate", objProp.EntryDate);
               objDAL.AddParameterToCommand("@TransactionMode", string.IsNullOrEmpty(objProp.TransactionMode) == true ? " " : objProp.TransactionMode);
               objDAL.AddParameterToCommand("@PurPose_Id", objProp.PurPose_Id);
               objDAL.AddParameterToCommand("@PaymentMode_Id", objProp.PaymentMode_Id);
               objDAL.AddParameterToCommand("@Currency_Id", objProp.Currency_Id);
               objDAL.AddParameterToCommand("@User_Id", objProp.User_Id);
               


               //if (objProp.TransactionMode == DBNull.Value)  
                
               
               objDAL.AddOutPutParameter();

               Int32 returnValue;
               returnValue = objDAL.DLLExecuteNonQuery(PRCINS);

               return returnValue;



           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
               objDAL.ClearParameter();
               objDAL.DatabaseClose();
           }
       }

       public Int32 Update(Transaction_MasterProperty objProp)
       {
           try
           {
               objDAL = new DataAccess();

               objDAL.CreateCommand(PRCUPD);

               objDAL.AddParameterToCommand("@Trans_Id", objProp.Trans_Id);
               objDAL.AddParameterToCommand("@Description", objProp.Description);
               objDAL.AddParameterToCommand("@Amount", objProp.Amount);
               objDAL.AddParameterToCommand("@Category_Id", objProp.Category_Id);
               objDAL.AddParameterToCommand("@EntryDate", objProp.EntryDate);
               objDAL.AddParameterToCommand("@TransactionMode", string.IsNullOrEmpty(objProp.TransactionMode) == true ? " " : objProp.TransactionMode);
               objDAL.AddParameterToCommand("@PurPose_Id", objProp.PurPose_Id);
               objDAL.AddParameterToCommand("@PaymentMode_Id", objProp.PaymentMode_Id);
               objDAL.AddParameterToCommand("@Currency_Id", objProp.Currency_Id);
               objDAL.AddParameterToCommand("@User_Id", objProp.User_Id);
               
               objDAL.AddOutPutParameter();

               Int32 returnValue;
               returnValue = objDAL.DLLExecuteNonQuery(PRCUPD);

               return returnValue;



           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
               objDAL.ClearParameter();
               objDAL.DatabaseClose();
           }
       }

       public Int32 Delete(Int32 TransId)
       {
           try
           {
               objDAL = new DataAccess();

               objDAL.CreateCommand(PRCDEL);

               objDAL.AddParameterToCommand("@Trans_Id", TransId);
               objDAL.AddOutPutParameter();

               Int32 returnValue;
               returnValue = objDAL.DLLExecuteNonQuery(PRCDEL);

               return returnValue;



           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
               objDAL.ClearParameter();
               objDAL.DatabaseClose();
           }
       }

       public Transaction_MasterProperty GetDataByPK(Int32 TransId)
       {
           try
           {
               SqlDataReader objReader = null;
               Transaction_MasterProperty objProp = new Transaction_MasterProperty();

               objDAL = new DataAccess();
               objDAL.CreateCommand(PRCGETBYID);

               objDAL.AddParameterToCommand("@Trans_Id", TransId);

               objReader = objDAL.ExecuteDataReader(PRCGETBYID);

               if (objReader.HasRows)
               {
                   objReader.Read();

                   objProp.Trans_Id = (Int32)(objReader["Trans_Id"]);
                   if (objReader["Description"] != DBNull.Value)
                   {
                       objProp.Description = (string)(objReader["Description"]);
                   }
                   if (objReader["Amount"] != DBNull.Value)
                   {
                       objProp.Amount = (double )(objReader["Amount"]);
                   }
                   if (objReader["Category_Id"] != DBNull.Value)
                   {
                       objProp.Category_Id = (int )(objReader["Category_Id"]);
                   }
                   if (objReader["EntryDate"] != DBNull.Value)
                   {
                       objProp.EntryDate = (DateTime )(objReader["EntryDate"]);
                   }
                   if (objReader["TransactionMode"] != DBNull.Value)
                   {
                       objProp.TransactionMode = (string )(objReader["TransactionMode"]);
                   }
                   if (objReader["PurPose_Id"] != DBNull.Value)
                   {
                       objProp.PurPose_Id = (int)(objReader["PurPose_Id"]);
                   }
                   if (objReader["PaymentMode_Id"] != DBNull.Value)
                   {
                       objProp.PaymentMode_Id = (int)(objReader["PaymentMode_Id"]);
                   }
                   if (objReader["Currency_Id"] != DBNull.Value)
                   {
                       objProp.Currency_Id = (int)(objReader["Currency_Id"]);
                   }
                   if (objReader["User_Id"] != DBNull.Value)
                   {
                       objProp.User_Id = (int)(objReader["User_Id"]);
                   }

               }
               objReader.Close();
               return objProp;
           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
               objDAL.ClearParameter();
               objDAL.DatabaseClose();
           }

       }

       public DataTable GetData(string SearchCriteria)
       {
           try
           {
               SqlDataReader objReader = null;

               objDAL = new DataAccess();
               objDAL.CreateCommand(PRCGETBYPARAM);


               objDAL.AddParameterToCommand("@SearchParam ", SearchCriteria);


               objReader = objDAL.ExecuteDataReader(PRCGETBYPARAM);

               DataTable dtTable = new DataTable();
               dtTable.Load(objReader);

               objReader.Close();

               return dtTable;

           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
               objDAL.ClearParameter();
               objDAL.DatabaseClose();
           }
       }

       public DataTable GetDataMainReport(string SearchCriteria)
       {
           try
           {
               SqlDataReader objReader = null;

               objDAL = new DataAccess();
               objDAL.CreateCommand(PRCGETMAINREPORT);


               objDAL.AddParameterToCommand("@SearchParam ", SearchCriteria);


               objReader = objDAL.ExecuteDataReader(PRCGETMAINREPORT);

               DataTable dtTable = new DataTable();
               dtTable.Load(objReader);

               objReader.Close();

               return dtTable;

           }
           catch (Exception ex)
           {
               throw ex;
           }
           finally
           {
               objDAL.ClearParameter();
               objDAL.DatabaseClose();
           }
       }


       #endregion
    }
}

-------------------------------------------------------------------------------

No comments:

Post a Comment