TechEthical CEHP

Current Path : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/
Upload File :
Current File : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/PaidCurrentAffairs.aspx.cs

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 PaidCurrentAffairs : System.Web.UI.Page
	{
        public System.Data.DataTable dt = new System.Data.DataTable();
        public System.Data.SqlClient.SqlDataAdapter SqlAdapter = new SqlDataAdapter();

        public string TableName = "tbl_PaidCurrentAffairs";
        public string StoredProcedure = "sp_PaidCurrentAffairs";

		 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");
                }

                DataTable ds = new DataTable();
                ds = obj.getDataTable("select name from tbl_Courses order by name");
                cmbCourse.DataSource = ds;
                cmbCourse.DataTextField = "name";
                cmbCourse.DataValueField = "name";
                cmbCourse.DataBind();
                
                BindGrid();    // SHOW EMPLOYEE DETAILS IN THE GRIDVIEW.
            }

        }

         public DataTable BindCource()
         {
             DataTable dt = new DataTable();
             connection_sql obj = new connection_sql();
             obj.MakeConnection();
             dt = obj.getDataTable("select name from tbl_Courses order by Name");
             obj.CloseConnection();
             return dt;
         }

        protected void butSave_Click(object sender, EventArgs e)
        {
            if (!FileUpload1.HasFile)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Attached File 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("/OnlineStudy/CurrentAffairs/") + FileUpload1.FileName);

                    connection_sql obj = new connection_sql();
                    obj.MakeConnection();

                    SqlCommand cmd = new SqlCommand(StoredProcedure, obj.conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Name", txtName.Text);
                    cmd.Parameters.AddWithValue("@Types", txtTypes.Text);
                    cmd.Parameters.AddWithValue("@Course", cmbCourse.Text);
                    cmd.Parameters.AddWithValue("@Subject", txtSubjectEntry.Text);
                    cmd.Parameters.AddWithValue("@Batch", txtBatch.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 = "";
                        txtBatch.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 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, "
                + " Course, Subject, Batch, Types, Dates, Description, Path, Status FROM dbo.[" + TableName + "] 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)
            {
                DropDownList cmbCourse2 = (DropDownList)e.Row.FindControl("cmbCourse2");
                string SelectedText = DataBinder.Eval(e.Row.DataItem, "Course").ToString();
                cmbCourse2.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 txtBatch2 = (TextBox)e.Row.FindControl("txtBatch2");
                string Dates = DataBinder.Eval(e.Row.DataItem, "Batch").ToString();
                txtBatch2.Text = Dates;
            }

            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 Course = (GridView.Rows[e.RowIndex].FindControl("cmbCourse2") 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 Batch = (GridView.Rows[e.RowIndex].FindControl("txtBatch2") 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(StoredProcedure, obj.conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Name", Name);
                cmd.Parameters.AddWithValue("@Types", Types);
                cmd.Parameters.AddWithValue("@Subject", Subject);
                cmd.Parameters.AddWithValue("@Course", Course);
                cmd.Parameters.AddWithValue("@Dates", Dates);
                cmd.Parameters.AddWithValue("@Batch", Batch);
                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." + TableName + " WHERE ID = " + _ID);
                lblUpdate.Text = "Record has been delete successfully.";
                Response.Redirect(Request.Url.AbsoluteUri);

                BindGrid();
            }

        }

        protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string _ID = GridView.DataKeys[e.RowIndex].Value.ToString();

            connection_sql obj = new connection_sql();
            obj.MakeConnection();
                SqlCommand cmd = new SqlCommand(StoredProcedure, obj.conn);
                
                obj.ExcuteCommand("Delete from dbo." + TableName + " 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