TechEthical CEHP
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Directory;
using System.Data;
using System.Data.SqlClient;
namespace Bathuasoft.admin
{
public partial class ImportantButtons : System.Web.UI.Page
{
public System.Data.DataTable dt = new System.Data.DataTable();
public System.Data.SqlClient.SqlDataAdapter SqlAdapter = new SqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{
connection_sql obj = new connection_sql();
obj.MakeConnection();
if (!IsPostBack)
{
if (Session["Loginxtr"].ToString() != "1254lkjhhfdgftfrdgf")
{
Response.Redirect("login.aspx");
}
PopulateDS(); // FILL DATASET WITH MASTER DATA.
ShowNewsDetails(); // SHOW EMPLOYEE DETAILS IN THE GRIDVIEW.
}
}
protected void butSave_Click(object sender, EventArgs e)
{
connection_sql obj = new connection_sql();
obj.MakeConnection();
int x = obj.ExcuteCommand("INSERT INTO tbl_ImportantButtons ([Name], OrderNo, [Link]) "
+ " VALUES('" + txtName.Text.Trim() + "', " + cmbOrderNo.Text + ", '" + txtLink.Text.Trim() + "')");
obj.CloseConnection();
if (x>0)
{
ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Save Successfully');", true);
ShowNewsDetails();
txtName.Text = "";
txtLink.Text = "";
}
}
// CANCEL ROW EDITING.
protected void GridView_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
{
GridView.EditIndex = -1;
ShowNewsDetails();
}
// ROW EDITING
protected void GridView_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
ShowNewsDetails();
lblUpdate.Text = "";
}
private void PopulateDS()
{
dt.Clear();
connection_sql obj = new connection_sql();
obj.MakeConnection();
dt = obj.getDataTable(@"SELECT ROW_NUMBER() OVER (ORDER BY Name) AS 'Sr No', ID, Name, OrderNo, Link, Status
FROM [tbl_ImportantButtons] order by OrderNo ");
}
private void ShowNewsDetails()
{
dt.Clear();
connection_sql obj = new connection_sql();
obj.MakeConnection();
dt = obj.getDataTable(@"SELECT ROW_NUMBER() OVER (ORDER BY ID) AS 'Sr No', ID, Name, OrderNo, Link, Status
FROM tbl_ImportantButtons order by id desc");
GridView.DataSource = dt;
GridView.DataBind();
obj.CloseConnection();
}
protected void GridView_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
DropDownList drpStatus = (DropDownList)e.Row.FindControl("drpStatus");
string SelectedText = DataBinder.Eval(e.Row.DataItem, "Status").ToString();
drpStatus.Items.FindByText(SelectedText).Selected = true;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtName = (TextBox)e.Row.FindControl("txtName");
string Text = DataBinder.Eval(e.Row.DataItem, "Name").ToString();
txtName.Text = Text;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtOrderNo = (TextBox)e.Row.FindControl("txtOrderNo");
string OrderNo = DataBinder.Eval(e.Row.DataItem, "OrderNo").ToString();
txtOrderNo.Text = OrderNo;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtLink = (TextBox)e.Row.FindControl("txtLink");
string Link = DataBinder.Eval(e.Row.DataItem, "Link").ToString();
txtLink.Text = Link;
}
}
protected void UpdateStatus(object sender, GridViewUpdateEventArgs e)
{
string Status = (GridView.Rows[e.RowIndex].FindControl("drpStatus") as DropDownList).SelectedItem.Text;
string Name = (GridView.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text;
string OrderNo = (GridView.Rows[e.RowIndex].FindControl("txtOrderNo") as TextBox).Text;
string Link = (GridView.Rows[e.RowIndex].FindControl("txtLink") as TextBox).Text;
string _ID = GridView.DataKeys[e.RowIndex].Value.ToString();
connection_sql obj = new connection_sql();
obj.MakeConnection();
if (Status!="Delete")
{
obj.ExcuteCommand("UPDATE [tbl_ImportantButtons] SET Status = '" + Status + "', Name ='" + Name + "'"
+ ", link='" + Link +"', OrderNo= 0" + OrderNo + " WHERE ID = " + _ID);
lblUpdate.Text = "Record updated successfully.";
Response.Redirect(Request.Url.AbsoluteUri);
}
else
{
obj.ExcuteCommand("Delete [tbl_ImportantButtons] WHERE ID = " + _ID);
lblUpdate.Text = "Record has been delete successfully.";
Response.Redirect(Request.Url.AbsoluteUri);
ShowNewsDetails();
}
}
}
}
TechEthical Mini WebShell Version 1.0, Coded By The_M@T3