$%@ Page Language="C#" %#
$%@ Import Namespace="System.Data" %#
$!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"#
$script runat="server"#
//TODO:
// Create an Object of the DataTable You need class for
// Assign Connection string name from Web.config
// Assign Data Set Name
clsFINANCE.FI_GRPHDSMSTDataTable dt = new clsFINANCE.FI_GRPHDSMSTDataTable();
public string TableName
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = tblName.Replace("FI_", "");
return tblName;
}
}
public string ClassName
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = "cls" + tblName.Replace("FI_", "") + "_DA";
return tblName;
}
}
public string CDO
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = "cls" + tblName.Replace("FI_", "") + "_CDO";
return tblName;
}
}
public string objCDO
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = tblName.Replace("FI_", "") + "_CDO";
return tblName;
}
}
public string ConnectionStringName = "dbConnectionString";
public string DataSetName = "clsFINANCE";
public StringBuilder param = new StringBuilder();
$/script#
$html xmlns="http://www.w3.org/1999/xhtml"#
$head runat="server"#
$title#DA Code Generator$/title#
$/head#
$body#
$form id="form1" runat="server"#
$div#
$pre#
using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.OracleClient;
using System.Collections;
using FinanceClassLib.Master.DA;
/*
Company Name : Dharmik Infotech, Ahmedabad
Project Name : !BBM$ (Integrated Blood Bank Management System)
Module : Blood Collection and Testing
Create By : Rajesh Prajapati
Create Date : $%= DateTime.Now %#
Purpose : For $%= dt.TableName%#
Modify By :
Modify Date :
Modify Purpose :
*/
namespace FinanceClassLib.Master.DA
{
public class $%=ClassName%# : clsCommon_DA
{
public clsConnection conn;
public $%=ClassName%#()
{
//
// TODO: Add constructor logic here
//
}
/*
Function For Getting All Records from Table $%=TableName %#
*/
public DataSet GetAll$%= dt.TableName%#($%=CDO %# $%=objCDO %#)
{
DataSet ds = new DataSet();
try
{
ObjectCreation();
CreateParameters($%=objCDO %#,ref command,"Select","GET_ALL_$%=TableName %#");
return ds;
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
/*
Function For Get Record By Id
*/
public DataSet Get$%= dt.TableName%#ById( $%=CDO %# $%=objCDO %#)
{
DataSet ds = new DataSet();
try
{
ObjectCreation();
CreateParameters($%=objCDO %#,ref command,"SelectById","GET_$%=TableName %#_BY_ID");
return ds;
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
/*
Function For Save and Update Records
*/
public Boolean Save_$%= dt.TableName%#(ref $%=CDO %# $%=objCDO %#,string command_type)
{
try
{
string strQuery = "";
ObjectCreation();
if (command_type == "Save")
{
strQuery = " SELECT COUNT(*) FROM $%=TableName %# WHERE colName = '"+$%=objCDO %#.colName +"'";
if (int.Parse(conn.Oracle_ExecuteScalar(strQuery)) != 0)
{
return false;
}
CreateParameters($%=objCDO %#,ref command,command_type,"ADD_$%=TableName %#");
if(conn.Oracle_ExecuteNonQuery(command))
return true;
}
else
{
strQuery = " SELECT COUNT(*) FROM $%=TableName %# WHERE colName = '"+$%=objCDO %#.colName +"'";
$% foreach (DataColumn col in dt.PrimaryKey)
{ %# strQuery = strQuery + " and $% =col.ColumnName%# != '"+ $%=objCDO %#.$%=col.ColumnName %#+"'";$% } %#
if (int.Parse(conn.Oracle_ExecuteScalar(strQuery)) != 0)
{
return false;
}
CreateParameters($%=objCDO %#,ref command,command_type,"UPDATE_$%=TableName %#");
if(conn.Oracle_ExecuteNonQuery(command))
return true;
}
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
return false;
}
/*
Function For Delete Record By Id
*/
public Boolean Delete_$%= dt.TableName%#(ref $%=CDO %# $%=objCDO %#,string strCommandName)
{
try
{
ObjectCreation();
CreateParameters($%=objCDO %#,ref command,strCommandName,"DELETE_$%=TableName %#");
return conn.Oracle_ExecuteNonQuery(command);
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
/*
Function For Create Parameters
*/
private void CreateParameters($%=CDO %# $%=objCDO %#,ref OracleCommand command,string strCommandName,string strprcname)
{
try
{
command = new OracleCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = strprcname;
command.Connection = conn.Get_Connection();
if (strCommandName=="Delete" || strCommandName== "SelectById" || strCommandName=="Update")
{
$% foreach (DataColumn col in dt.PrimaryKey)
{ %# command.Parameters.Add("V_$% =col.ColumnName%#", $%=objCDO %#.$%=col.ColumnName %#);$% } %#
}
if(strCommandName=="Save" || strCommandName=="Update")
{$% foreach (DataColumn col in dt.Columns)
{ %#
command.Parameters.Add("V_$% =col.ColumnName%#", $%=objCDO %#.$%=col.ColumnName %#); $%} %#
}
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
/*
Function For Create Object of Connection Class
*/
private void ObjectCreation()
{
try
{
conn = new clsConnection();
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
}
}
$/pre#
$/div#
$/form#
$/body#
$/html#
2/21/11
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment