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 AddResultsAssignmentsDocuments : 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.
BindGrid(); // SHOW EMPLOYEE DETAILS IN THE GRIDVIEW.
}
}
protected void butSave_Click(object sender, EventArgs e)
{
if (!FileUpload1.HasFile)
{
ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Name' Can't be blank.');", true);
}
else
{
if (txtName.Text=="" && txtDescription.Text =="")
{
ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Name & Description' both can't be blank.');", true);
}
else
{
FileUpload1.SaveAs(Server.MapPath("~/Documents/Notes/") + FileUpload1.FileName);
connection_sql obj = new connection_sql();
obj.MakeConnection();
SqlCommand cmd = new SqlCommand("sp_AddNotes", obj.conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Types", txtTypes.Text);
cmd.Parameters.AddWithValue("@Subject", txtSubjectEntry.Text);
cmd.Parameters.AddWithValue("@Dates", txtDateEntry.Text);
cmd.Parameters.AddWithValue("@Description", txtDescription.Text);
cmd.Parameters.AddWithValue("@Path", FileUpload1.FileName);
cmd.Parameters.AddWithValue("@Status", "Active");
cmd.Parameters.AddWithValue("@SQLCMD", "Add");
cmd.Parameters.AddWithValue("@ID", 0);
int k = cmd.ExecuteNonQuery();
obj.CloseConnection();
if (k==1)
{
txtName.Text="";
txtTypes.Text = "";
txtDescription.Text = "";
txtSubjectEntry.Text = "";
txtDateEntry.Text = "";
ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Save Successfully.');", true);
}
BindGrid();
}
}
}
// CANCEL ROW EDITING.
protected void GridView_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
{
GridView.EditIndex = -1;
BindGrid();
}
// ROW EDITING
protected void GridView_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
BindGrid();
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, Status
FROM [tbl_Courses] order by id ");
}
private void BindGrid()
{
dt.Clear();
connection_sql obj = new connection_sql();
obj.MakeConnection();
dt = obj.getDataTable(@"SELECT ROW_NUMBER() OVER (ORDER BY ID desc) AS 'Sr No', ID, Name, "
+ " Subject, Types, Dates, Description, Path, Status FROM dbo.[tbl_Notes] 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 txtName2 = (TextBox)e.Row.FindControl("txtName2");
string Name = DataBinder.Eval(e.Row.DataItem, "Name").ToString();
txtName2.Text = Name;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtSubject2 = (TextBox)e.Row.FindControl("txtSubject2");
string Subject = DataBinder.Eval(e.Row.DataItem, "Subject").ToString();
txtSubject2.Text = Subject;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtDates2 = (TextBox)e.Row.FindControl("txtDates2");
string Dates = DataBinder.Eval(e.Row.DataItem, "Dates").ToString();
txtDates2.Text = Dates;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtDescription2 = (TextBox)e.Row.FindControl("txtDescription2");
string Description = DataBinder.Eval(e.Row.DataItem, "Description").ToString();
txtDescription2.Text = Description;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtPath2 = (TextBox)e.Row.FindControl("txtPath2");
string Path = DataBinder.Eval(e.Row.DataItem, "Path").ToString();
txtPath2.Text = Path;
}
if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
{
TextBox txtTypes2 = (TextBox)e.Row.FindControl("txtTypes2");
string Types = DataBinder.Eval(e.Row.DataItem, "Types").ToString();
txtTypes2.Text = Types;
}
}
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("txtName2") as TextBox).Text;
string Types = (GridView.Rows[e.RowIndex].FindControl("txtTypes2") as TextBox).Text;
string Description = (GridView.Rows[e.RowIndex].FindControl("txtDescription2") as TextBox).Text;
string Subject = (GridView.Rows[e.RowIndex].FindControl("txtSubject2") as TextBox).Text;
string Dates = (GridView.Rows[e.RowIndex].FindControl("txtDates2") as TextBox).Text;
string Path = (GridView.Rows[e.RowIndex].FindControl("txtPath2") as TextBox).Text;
string _ID = GridView.DataKeys[e.RowIndex].Value.ToString();
connection_sql obj = new connection_sql();
obj.MakeConnection();
if (Status != "Delete")
{
SqlCommand cmd = new SqlCommand("sp_AddNotes", obj.conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Types", Types);
cmd.Parameters.AddWithValue("@Subject", Subject);
cmd.Parameters.AddWithValue("@Dates", Dates);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@Path", Path);
cmd.Parameters.AddWithValue("@Status", Status);
cmd.Parameters.AddWithValue("@SQLCMD", "Update");
cmd.Parameters.AddWithValue("@ID", _ID);
int k = cmd.ExecuteNonQuery();
obj.CloseConnection();
lblUpdate.Text = "Record updated successfully.";
Response.Redirect(Request.Url.AbsoluteUri);
}
else
{
obj.ExcuteCommand("Delete from dbo.tbl_Notes WHERE ID = " + _ID);
lblUpdate.Text = "Record has been delete successfully.";
Response.Redirect(Request.Url.AbsoluteUri);
BindGrid();
}
}
}
}
TechEthical Mini WebShell Version 1.0, Coded By The_M@T3