$%@ 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
//public aspnetdb.ModulePermissionDataTable dt = new aspnetdb.ModulePermissionDataTable();
// dsProduction.TBL_PRODUCTION_PROCESS_DETAIL_MACHINEDataTable dt = new dsProduction.TBL_PRODUCTION_PROCESS_DETAIL_MACHINEDataTable();
DataSet1.LoginDataTable dt = new DataSet1.LoginDataTable();
// CodeGenerator.TBL_ITEMPROPERTIESDataTable dt = new CodeGenerator.TBL_ITEMPROPERTIESDataTable();
public string TableName
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = tblName.Replace("TBL_", "");
return tblName;
}
}
public string ClassName
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName ="cls"+ tblName.Replace("TBL_", "") + "_DA";
return tblName;
}
}
public string CDO
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = "cls"+tblName.Replace("TBL_", "") + "_CDO";
return tblName;
}
}
public string objCDO
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = tblName.Replace("TBL_", "") + "_CDO";
return tblName;
}
}
public string ConnectionStringName = "sdmsConnectionString";
public string DataSetName = "CodeGenerator";
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.SqlClient;
using System.Collections;
using SDMClasslibrary.CONN;
using SDMClasslibrary.CDO.Master;
/*
COMPANY NAME : DHARMIK INFOTECH, AHMEDABAD
PROJECT NAME : SALES AND DESTRUCTION MANAGEMENT SYSTEM
CREATE BY : MAULIK, MITESH, ANKIT, PARUL, TEJAS
CREATE DATE : $%= DateTime.Now %#
PURPOSE : FOR $%= dt.TableName%#
MODIFY BY :
MODIFY DATE :
MODIFY PURPOSE :
TABLE USE : $%= dt.TableName%#
*/
namespace SDMClasslibrary.DA.Master
{
public class $%=ClassName%#
{
private SqlCommand command;
private Connection conn;
public $%=ClassName%#()
{
//
// TODO: Add constructor logic here
//
}
/*
Function For Getting all Records
*/
public DataSet View_$%=TableName %#($%=CDO %# $%=objCDO %#)
{
DataSet ds = new DataSet();
try
{
ObjectCreation();
CreateParameters($%=objCDO %#,ref command,"Select","$%=TableName %#_GetList");
conn.Sql_ExecuteQuery(command,ref ds);
return ds;
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
/*
Function For Save and Update Records
*/
public Boolean Save_$%=TableName %#(ref $%=CDO %# $%=objCDO %#,string command_type)
{
try
{
ObjectCreation();
if (command_type == "Save")
{
CreateParameters($%=objCDO %#,ref command,command_type,"$%=TableName %#_Insert");
if(conn.Sql_ExecuteQuery(command))
return true;
}
else
{
CreateParameters($%=objCDO %#,ref command,command_type,"$%=TableName %#_UPDATE");
if(conn.Sql_ExecuteQuery(command))
return true;
}
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
return false;
}
/*
Function For Get Record By Id
*/
public Boolean GetEditDeleteView( $%=CDO %# $%=objCDO %#, ref DataSet ds,string str_table)
{
try
{
ObjectCreation();
switch(str_table)
{
case "$%=TableName%#Edit":
CreateParameters($%=objCDO %#,ref command,str_table,"$%=TableName %#_GET");
break;
}
return conn.Sql_ExecuteQuery(command,ref ds,str_table);
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
/*
Function For Delete Record By Id
*/
public Boolean Delete_$%=TableName %#(ref $%=CDO %# $%=objCDO %#,string strCommandName)
{
try
{
ObjectCreation();
CreateParameters($%=objCDO %#,ref command,strCommandName,"$%=TableName %#_DELETE");
return conn.Sql_ExecuteQuery(command);
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
/*
Function For Create Parameters
*/
public void CreateParameters($%=CDO %# $%=objCDO %#,ref SqlCommand command,string strCommandName,string strprcname)
{
try
{
command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = strprcname;
command.Connection = conn.Get_Connection();
if (strCommandName=="Delete" || strCommandName== "$%=TableName%#Edit" || strCommandName=="Update")
{
$% foreach (DataColumn col in dt.PrimaryKey){ %#
command.Parameters.Add("@$% =col.ColumnName%#", $%=objCDO %#.$%=col.ColumnName %#);
$% } %#
}
if(strCommandName=="Save" || strCommandName=="Update")
{
$% foreach (DataColumn col in dt.Columns){ %#
command.Parameters.Add("@$% =col.ColumnName%#", $%=objCDO %#.$%=col.ColumnName %#);
$%} %#
}
if (strCommandName=="Select" )
{
$% foreach (DataColumn col in dt.PrimaryKey){ %#
command.Parameters.Add("@$% =col.ColumnName%#", $%=objCDO %#.$%=col.ColumnName %#);
$% } %#
}
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
/*
Function For Create Object of Connection Class
*/
public void ObjectCreation()
{
try
{
conn = new SDMClasslibrary.CONN.Connection();
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
}
}
$/pre#
$/div#
$/form#
$/body#
$/html#
2/20/11
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment