Tuesday, June 10, 2014

BACKBONE TUTORIAL 1 ( Backbone enable weather api )

Client side technology is rapidly growing up. Backbone is one of the best client side JavaScript library that runs in the browser which support MVC architecture.

Basic things to know about backbone.


  1. MODEL
  2. COLLECTION
  3. VIEW
  4. CONTROLLER
  5. ROUTE
  6. HISTORY

Backbone is top of Underscore.js, as well as jQuery, to provide a platform forbuilding applications.
For more you can follow below links.
http://underscorejs.org/
http://jquery.com/download/
http://backbonejs.org/



Sunday, March 25, 2012

Check post back happen which control...

/// Get Which html Controls cause Postback...
///
///
///
public static Control GetPostBackControl(Page page)
{
Control control = null;

string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
Control c = page.FindControl(ctl);
if (c is System.Web.UI.WebControls.Button)
{
control = c;
break;
}
}
}
return control;
}


===== C
all Method in Page Load======

string ctrlname = Page.Request.Params.Get("__EVENTTARGET");

Control _ctlPostback =GetPostBackControl(this.Page);

if (_ctlPostback != null)
{
#region
if (_ctlPostback.ClientID.ToString().Equals("ctl00_ContentPlaceHolder1__ddlPagerSize"))
{
int _intGetPagerSize = int.Parse(_ddlPagerSize.SelectedValue.ToString());
string _strGetFilter = _ddlFilter.SelectedValue.ToString();

_gridEmployeeList.PageSize = _intGetPagerSize;

BindGrid();
}
#endregion
}

Bind Grid View....

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class EmployeeList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// The Page is accessed for the first time.
if (!IsPostBack)
{
// Initialize the sorting expression.
ViewState["SortExpression"] = "EmployeeID";

BindGrid();
}
else
{

string ctrlname = Page.Request.Params.Get("__EVENTTARGET");

Control _ctlPostback =GetPostBackControl(this.Page);

if (_ctlPostback != null)
{
#region
if (_ctlPostback.ClientID.ToString().Equals("ctl00_ContentPlaceHolder1__ddlPagerSize"))
{
int _intGetPagerSize = int.Parse(_ddlPagerSize.SelectedValue.ToString());
string _strGetFilter = _ddlFilter.SelectedValue.ToString();

_gridEmployeeList.PageSize = _intGetPagerSize;

BindGrid();
}
#endregion
}
}
}



///


/// Get Which html Controls cause Postback...
///

///
///
public static Control GetPostBackControl(Page page)
{
Control control = null;

string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
Control c = page.FindControl(ctl);
if (c is System.Web.UI.WebControls.Button)
{
control = c;
break;
}
}
}
return control;
}




///
/// Fired when Cancel button is clicked
///

///
///
protected void CancelRecord(object sender, GridViewCancelEditEventArgs e)
{
_gridEmployeeList.EditIndex = -1;
BindGrid();
}


///
/// Fires when Edit button is clicked
///

///
///
protected void EditRecord(object sender, GridViewEditEventArgs e)
{
_gridEmployeeList.EditIndex = e.NewEditIndex;
BindGrid();
}

///
/// Fires when Update button is clicked
///

///
///
protected void UpdateRecord(object sender, GridViewUpdateEventArgs e)
{
//// Refresh the list
BindGrid();
}

///
/// fires when Delete button is clicked
///

///
///
protected void DeleteRecord(object sender, GridViewDeleteEventArgs e)
{
}

///
/// Fires when page links are clicked
///

///
///
protected void ChangePage(object sender, GridViewPageEventArgs e)
{
_gridEmployeeList.PageIndex = e.NewPageIndex;
// Refresh the list
BindGrid();
}

///
/// Fires when Columns heading are clicked
///

///
///
protected void SortRecords(object sender, GridViewSortEventArgs e)
{
}


///
/// Bind the gridview
///

private void BindGrid()
{
DataSet _dsGetEmployees = Employee.GetEmployees(true);

if (UIUtil.IsDataSetValidate(_dsGetEmployees))
{
// Set the sort column and sort order.
_gridEmployeeList.Sort(ViewState["SortExpression"].ToString(), SortDirection.Ascending);

// Bind the GridView control.
_gridEmployeeList.DataSource = _dsGetEmployees;
_gridEmployeeList.DataBind();
}
}


// Initialize the Employee List DataTable.
private void InitializeDataSource()
{
// Create a DataTable object named dtPerson.
DataTable dtPerson = new DataTable();
}


protected void _ddlPagerSize_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void _ddlFilter_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void _imgButAddEmployee_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("~/EmployeePage.aspx");
}


///
/// On Row Data Bound...
///

///
///
protected void _gridEmployeeList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton imgBut = (ImageButton)e.Row.FindControl("delbut");
imgBut.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "EmployeeID") + "')");
}
}

///
/// Delete Record....
///

///
///
protected void _gridEmployeeList_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int _intEmpIdtoUpdateStatus = Convert.ToInt32(e.CommandArgument);

if (_intEmpIdtoUpdateStatus > 0)
{
// Delete the record
bool _bIsUpdatedStatus = Employee.UpdateStatusEmployee(_intEmpIdtoUpdateStatus, false);
}

BindGrid();
}
}
}

Saturday, March 24, 2012

Db in web.config



Create Data Access class

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections;

///


/// Summary description for DataAccess
///

public class DataAccess
{
public DataAccess()
{
//
// TODO: Add constructor logic here
//
}

///
/// Get Data Set
///

///
/// DBRequest object
///
/// Data Set
#region Get Data Set...
public static DataSet GetDataSet(DBRequest _objDBRequest)
{
DataSet _dataSet = new DataSet();
bool _isOpenSqlConnection=false;

try
{
///Open Sql Connection...
_isOpenSqlConnection = _objDBRequest.OpenSQLConnection();

if (_isOpenSqlConnection)
{
///Sql Command...
SqlCommand _sqlCommand = new SqlCommand(_objDBRequest.SqlCommandText, _objDBRequest.SqlConnection);
_sqlCommand.CommandType = _objDBRequest.SqlComandType;
SqlParameter _sqlParameter = null;


///Get Sql Parameter...
Hashtable _parameterhashTbl = _objDBRequest.Parameter;

if (_parameterhashTbl.Count > 0)
{
foreach (string key in _parameterhashTbl.Keys)
{
_sqlParameter = (SqlParameter)_objDBRequest.Parameter[key];
_sqlCommand.Parameters.Add(_sqlParameter);
}
}

///Fill Dataset
SqlDataAdapter _sqlDataAdapter = new SqlDataAdapter(_sqlCommand);
_sqlDataAdapter.Fill(_dataSet);
}
}
catch (SqlException sqlExe)
{
_objDBRequest.Exception = sqlExe;
}
finally
{
if (_isOpenSqlConnection && _objDBRequest.SqlConnection.State == ConnectionState.Open)
{
///Close Sql Connection...
_objDBRequest.CloseSqlConnection();
}
}

return _dataSet;
}
#endregion

///
/// ExecuteNon Query...
///

///
///
#region ExecuteNon Query...
public static bool ExecuteNonQuery(DBRequest _objDBinsertRequest)
{
bool _isInsertedRow = false;
bool _isOpenSqlConnection = false;

try
{
_isOpenSqlConnection = _objDBinsertRequest.OpenSQLConnection();

if (_isOpenSqlConnection)
{
///Sql Command...
SqlCommand _sqlCommand = new SqlCommand(_objDBinsertRequest.SqlCommandText, _objDBinsertRequest.SqlConnection);
_sqlCommand.CommandType = _objDBinsertRequest.SqlComandType;
SqlParameter _sqlParameter = null;

///Get Sql Parameter...
Hashtable _parameterhashTbl = _objDBinsertRequest.Parameter;

if (_parameterhashTbl.Count > 0)
{
foreach (string key in _parameterhashTbl.Keys)
{
_sqlParameter = (SqlParameter)_objDBinsertRequest.Parameter[key];
_sqlCommand.Parameters.Add(_sqlParameter);
}
}

int _i=_sqlCommand.ExecuteNonQuery();

_isInsertedRow = true;
}
}
catch (Exception ex)
{
_isInsertedRow = false;
_objDBinsertRequest.Exception = ex;
}
finally
{
if (_isOpenSqlConnection && _objDBinsertRequest.SqlConnection.State == ConnectionState.Open)
{
///Close Sql Connection...
_objDBinsertRequest.CloseSqlConnection();
}
}

return _isInsertedRow;
}
#endregion
}

Create Db Request class

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections;

///


/// Summary description for DBRequest
///

public class DBRequest
{
///
/// Connection String...
///

private string _sConnectionString;
public string ConnectionString
{
get { return _sConnectionString; }
set { _sConnectionString = value; }
}

///
/// SQl Connecion...
///

private SqlConnection _sqlConnection;
public SqlConnection SqlConnection
{
get { return _sqlConnection; }
set { _sqlConnection = value; }
}

private string _sqlCommandText;
public string SqlCommandText
{
get { return _sqlCommandText; }
set { _sqlCommandText = value; }
}

private CommandType _sqlComandType;
public CommandType SqlComandType
{
get { return _sqlComandType; }
set { _sqlComandType = value; }
}

private Hashtable _parameter = new Hashtable();
public Hashtable Parameter
{
get { return _parameter; }
set { _parameter = value; }
}

private Exception _exception;
public Exception Exception
{
get { return _exception; }
set { _exception = value; }
}

public DBRequest()
{
ConnectionString = GetSQLConnectionString();

}

///
/// Get SQL Connection String...
///

/// SQL Connection String
#region Get SQL Connection String
public string GetSQLConnectionString()
{
return Config.ConnectionString.ToString();
}
#endregion

///
/// Open Sql Connecion....
///

/// True = if Open Success...
/// False = if open not success...
///

public bool OpenSQLConnection()
{
bool isOpenSqlConnecion=false;

try
{
///Get Sql Connecion String....
string _sGetConnectionString = GetSQLConnectionString();

if(!string.IsNullOrEmpty(_sGetConnectionString))
{
///Open Sql Connection.....
SqlConnection = new SqlConnection(_sGetConnectionString);
SqlConnection.Open();

isOpenSqlConnecion=true;
}
}
catch(SqlException sqlEx)
{
isOpenSqlConnecion=false;
throw sqlEx;
}

return isOpenSqlConnecion;
}

///
/// Close Sql Connceion...
///

/// True=if closed success
/// False=if close not success
///

public bool CloseSqlConnection()
{
bool isClosedSqlConnecion = false;

try
{
///Check Sql Connection is Exits....
if (SqlConnection != null)
{
if (SqlConnection.State != ConnectionState.Broken || SqlConnection.State != ConnectionState.Closed)
{
///Close Sql Connection....
SqlConnection.Close();

isClosedSqlConnecion = true;
}
}
else
{
isClosedSqlConnecion = false;
}
}
catch (SqlException sqlEx)
{
isClosedSqlConnecion = false;
throw sqlEx;
}
return isClosedSqlConnecion;
}

///
/// Get Sql Connection
///

///
public SqlConnection GetSQLConnection()
{
SqlConnection _sqlConn = SqlConnection;

return _sqlConn;
}


///
/// Add Sql Parameter....
///

/// Parameter Name
/// Parameter Db Type
/// Parameter Value
/// Parameter Direction
public void AddSqlParameter(string parameterName, SqlDbType sqlDbType,object objSqlParameterValue,ParameterDirection parameterDirection)
{
try
{
SqlParameter _sqlParameter = new SqlParameter(parameterName,sqlDbType);

if (_sqlParameter != null)
{
_sqlParameter.Value = objSqlParameterValue;
_sqlParameter.Direction = parameterDirection;

Parameter.Add(parameterName, _sqlParameter);
}
}
catch (SqlException SqlExce)
{
throw SqlExce;
}
}
}

DB configaration How to Get Sql connection String.

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

///


/// Summary description for Config
///

public class Config
{
public Config()
{
//
// TODO: Add constructor logic here
//
}


///
/// Connection String....
///

public static string ConnectionString
{
get { return ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString.ToString(); }
}

///
/// get Db schema...
///

public static string DBSchemaName
{
get { return "[" + ConfigurationManager.AppSettings["dbUsr"].ToString() + "]"; }
}


}

About This Blog

  © Blogger templates 'Neuronic' by Ourblogtemplates.com 2008

Back to TOP