$%@ 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
//dsCPI.MK_STKTRANSFDTLDataTable dt = new dsCPI.MK_STKTRANSFDTLDataTable();
//dsCRI.MK_PATINSTREQNMSTDataTable dt = new dsCRI.MK_PATINSTREQNMSTDataTable();
// dsCRI.MK_INCOMPTDataTable dt = new dsCRI.MK_INCOMPTDataTable();
// dsBCT.BL_PRODMSTDataTable dt = new dsBCT.BL_PRODMSTDataTable();
/// dsMarketing.MK_BLDDRVMSTDataTable dt = new dsMarketing.MK_BLDDRVMSTDataTable();
dsMarketing.CP_OTHERDataTable dt = new dsMarketing.CP_OTHERDataTable();
//DataSet1.BL_REASONMSTDataTable dt = new DataSet1.BL_REASONMSTDataTable();
// DataTable dt = new DataTable();
public string TableName
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = GetTableName(tblName.Replace("CP_", ""));
return tblName;
}
}
public string ClassName
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = "cls" + GetTableName(tblName.Replace("CP_", "")) + "_CDO";
return tblName;
}
}
public string ClassNameDA
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = "cls" + GetTableName(tblName.Replace("CP_", "")) + "_DA";
return tblName;
}
}
public string ObjectNameCDO
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = GetTableName(tblName.Replace("CP_", "")) + "_CDO";
return tblName;
}
}
public string ObjectNameDA
{
get
{
String tblName = dt.TableName.Replace("DataTable", "");
tblName = GetTableName(tblName.Replace("CP_", "")) + "_DA";
return tblName;
}
}
private string GetTableName(string name)
{
return name;
bool isMethodName = true;
if (!isMethodName && name.StartsWith("V_"))
{
name = name.Substring(2);
}
StringBuilder bld = new StringBuilder();
bool lastDash = false;
int i = 0;
foreach (char c in name)
{
if (c == '_')
{
lastDash = true;
}
else
{
if (lastDash)
{
bld.Append(c);
}
else
{
if (isMethodName && i == 0)
{
bld.Append(c);
}
else
{
bld.Append(char.ToLower(c));
}
}
lastDash = false;
}
i++;
}
return bld.ToString();
}
public string ConnectionStringName = "dbConnectionString";
public string DataSetName = "CodeGenerator";
public StringBuilder param = new StringBuilder();
$/script#
$html xmlns="http://www.w3.org/1999/xhtml"#
$head id="Head1" runat="server"#
$title#Untitled Page$/title#
$/head#
$body#
$form id="form1" runat="server"#
$div#
$pre#
/*
COMPANY NAME : Dharmik Infotech
PROJECT NAME : iBBM$ (Integrated Blood Bank Management System)
MODULE NAME : Component Reservation And Issue
CREATE BY : Rajesh Prajapati
CREATE DATE : $%= DateTime.Now%#
PURPOSE : FOR $%= dt.TableName%#
MODIFY BY :
MODIFY DATE :
MODIFY PURPOSE :
REMARKS :
*/
using Ibbms.Security;
using CRILib.Transaction.CDO;
using CRILib.Transaction.DA;
protected void Page_Load(object sender, EventArgs e)
{
ctrlHeader.GridRowCommand += new Search_GridSearch.RowCommand(Search_GridSearch_RowCommand);
ctrlHeader.AddClick += new Search_GridSearch.Click(Add_Click);
if (!Page.IsPostBack)
{
clsUserMenuRights UserMenuRights = new clsUserMenuRights();
if (!UserMenuRights.Assign_Rights(Request.ApplicationPath, Request.CurrentExecutionFilePath, Session["USERNAME"] == null ? "" : Session["USERNAME"].ToString()))
Response.Redirect(UserMenuRights.Redirectpath);
ViewState["Add_new"] = UserMenuRights.Add_flag;
ctrlHeader.Edit = UserMenuRights.Edit_flag;
ctrlHeader.Delete = UserMenuRights.Del_flag;
ctrlHeader.View = UserMenuRights.view_flag;
ctrlHeader.Add = UserMenuRights.Add_flag;
SetPanel(true);
}
}
#region "Private Function"
//Set Panel
private void SetPanel(bool flg)
{
pnlGrid.Visible = flg;
pnlTrans.Visible = !flg;
}
//Clear Text Function
private void ClearText()
{
$%
foreach (DataColumn col in dt.Columns)
{
%# txt$%=col.ColumnName%#.Text =String.Empty ;
$%
}
%#
}
//Enabled-Disabled Control Function
private void setText(Boolean flg)
{
$%
foreach (DataColumn col in dt.Columns)
{
%# txt$%=col.ColumnName%#.Enabled =flg;
$%
}
%#
}
//Readonly control
private void setReadonly(Boolean flg)
{
$%
foreach (DataColumn col in dt.Columns)
{
%# txt$%=col.ColumnName%#.ReadOnly =flg;
$%
}
%#
}
//Load Form Data in to CDO
private void Load_Data(ref $%=ClassName%# $%=ObjectNameCDO%#)
{
$%
foreach (DataColumn col in dt.Columns)
{
if ("String" != col.DataType.Name.ToString())
{ %#
$%=ObjectNameCDO%#.$%=col.ColumnName%# = $%=col.DataType.Name%#.Parse( txt$%=col.ColumnName%#.Text);
$% }
else
{ %#
$%=ObjectNameCDO%#.$%=col.ColumnName%# = txt$%=col.ColumnName%#.Text;
$% }%#
$%
}
%#
}
// set data rows value to controls
private void setValues(DataSet ds)
{
$%
foreach (DataColumn col in dt.Columns)
{
%#txt$%=col.ColumnName%#.Text = ds.Tables[0].Rows[0]["$%=col.ColumnName%#"].ToString();
$%
}
%#
}
// Common Switch case Function For Save Data
// common function for Save, Update, Delete Records
private Boolean Common_Switch_Case(string strCommandName)
{
Boolean Blnflg=false;
try
{
$%=ClassName %# $%=ObjectNameCDO %# =new $%=ClassName%#();
$%=ClassNameDA %# $%=ObjectNameDA%# = new $%=ClassNameDA%#();
$%=ObjectNameCDO %#.COLOCN_C = Session["COLOCN_C"].ToString();
if (strCommandName != "Delete") Load_Data(ref $%=ObjectNameCDO%#);
if (strCommandName != "Save") $%=ObjectNameCDO%#.$%= dt.TableName %#Id = Int64.Parse(ViewState["$%=dt.TableName%#Id"].ToString());
if (strCommandName != "Delete")
Blnflg = $%=ObjectNameDA%#.Save_$%=TableName%#(ref $%=ObjectNameCDO%#,strCommandName);
else
Blnflg = $%=ObjectNameDA%#.Delete_$%=TableName%#(ref $%=ObjectNameCDO%#,strCommandName);
}
catch(Exception ex)
{
Session["ex"] = ex;
throw new Exception(ex.Message,ex);
}
return Blnflg;
}
// Grid Binding Function
private void Bind_Grid()
{
try
{
ctrlHeader.Bind_Grid() ;
}
catch(Exception ex)
{
Session["ex"] = ex;
throw new Exception(ex.Message,ex);
}
}
// DropDownList Binding Function
private DropDownList BindListBox(DropDownList ddlList, DataSet ds,string TextFields,string ValueFields)
{
ddlList.DataSource=ds;
ddlList.DataTextField=TextFields;
ddlList.DataValueField=ValueFields;
ddlList.DataBind();
if (ddlList.Items.Count#0)
{
ddlList.SelectedIndex=-1;
}
return ddlList;
}
#endregion
#region "Button Events"
// code for Save Button
protected void btnSave_Click(object sender, System.EventArgs e)
{
Boolean Blnflg=false;
if(btnSave.Text=="Save")
Blnflg=Common_Switch_Case("Save");
else if(btnSave.Text=="Update")
Blnflg=Common_Switch_Case("Update");
try
{
if (Blnflg)
{
lblstatus_msg.Text = " Record has been saved succesfully";
lblstatus_msg.ForeColor = System.Drawing.Color.Green;
}
else
{
lblstatus_msg.Text = " Record Already Exist";
lblstatus_msg.ForeColor = System.Drawing.Color.Red;
}
SetPanel(false);
Bind_Grid();
}
catch(Exception ex)
{
Session["ex"] = ex;
throw new Exception(ex.Message,ex);
}
}
// code for cancel button
protected void btnCancel_Click(object sender, System.EventArgs e)
{
try
{
btnCancel.Text="Cancel";
lblstatus_msg.Text="";
Bind_Grid();
btnSave.Visible=true;
btnAddNew.Visible = true;
SetPanel(true);
}
catch(Exception ex)
{
Session["ex"] = ex;
throw new Exception(ex.Message,ex);
}
}
// add new button click event
protected void btnAddNew_Click(object sender, System.EventArgs e)
{
try
{
ClearText();
setText(true);
SetPanel(false);
btnSave.Text="Save";
lblstatus_msg.Text="";
}
catch(Exception ex)
{
Session["ex"] = ex;
throw new Exception(ex.Message,ex);
}
}
#endregion
#region "Grid Events"
// GRID VIEW DELETE ROWS COMMAND
private void Add_Click(object sender, EventArgs e)
{
btnAddNew_Click(sender, e);
}
//GRID VIEW EVENTS
private void Search_GridSearch_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "View" || e.CommandName == "Edit" || e.CommandName == "Delete")
{
String Id = "";
Id = ctrlHeader.PrimaryKey;
$%=ClassName %# $%=ObjectNameCDO %# =new $%=ClassName%#();
$%=ClassNameDA %# $%=ObjectNameDA%# = new $%=ClassNameDA%#();
$%=ObjectNameCDO %#_CDO.COLOCN_C = Session["COLOCN_C"].ToString();
$%=ObjectNameCDO %#.EQUCONDITONID = decimal.Parse(Id);
ViewState["EQUCONDITONID"] = Id;
txtEQUCONDITONID.Text = Id;
if (e.CommandName == "Edit" || e.CommandName == "View")
{
DataSet dsReturn = new DataSet();
dsReturn = $%=ObjectNameDA%#.Get$%=TableName%#By_Id( $%=ObjectNameCDO%# );
setValues(dsReturn);
if (e.CommandName == "Edit")
{
setText(true);
btnSave.Visible = true;
btnCancel.Visible = true;
btnSave.Text = "Update";
}
else
{
setText(false);
btnSave.Visible = false;
btnCancel.Visible = true;
}
SetPanel(false);
}
else
{
Common_Switch_Case("Delete");
ctrlHeader.Bind_Grid();
lblstatus_msg.Text = "Record Delete Sucessfully";
}
}
}
#endregion
$/pre#
$/div#
$/form#
$/body#
$/html#
2/21/11
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment