TechEthical CEHP

Current Path : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/
Upload File :
Current File : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/CourseEntry.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 CourseEntry : System.Web.UI.Page
	{
        public System.Data.DataTable dt = new System.Data.DataTable();
        public System.Data.SqlClient.SqlDataAdapter SqlAdapter = new SqlDataAdapter();
        public string ImagePath = "";

        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)
        {

            if (txtName.Text.Trim() == "")
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Name can not be blank');", true);
                return;
            }

            if (txtHeading.Text.Trim() == "")
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Heading can not be blank');", true);
                return;
            }

            if (txtPageTitle.Text.Trim() == "")
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Page Title can not be blank');", true);
                return;
            }

            if (txtMenuURL.Text.Trim() == "")
                txtMenuURL.Text = txtName.Text.Replace(":", "-").Replace("&", "-").Replace(" ", "-").Replace("/", "-").ToString();

             if (butSave.Text == "Save")
             {

            connection_sql obj = new connection_sql();
            obj.MakeConnection();
            string qry = "INSERT INTO [tbl_Courses] (Name,PageTitle, Heading, contant,ShortContent, Status, UrlName, MenuList) " 
                 + " VALUES('" + txtName.Text.Trim() + "','" + txtPageTitle.Text.Trim() + "','" 
                 + txtHeading.Text.Trim() + "','" + txtFullContents.Text.Trim() + "','" 
                 + txtShortContent.Text.Trim() + "', 'Active', " 
                 + "'" + txtMenuURL.Text + "', '" + cmbMenuList.Text + "')";
            SqlCommand cmd = new SqlCommand(qry, obj.conn);
           
           cmd.ExecuteNonQuery();

           btnMainImageFileUpload_Click(sender,e);
           ShowNewsDetails();
            ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Submit Successfully');", true);
            obj.CloseConnection();
             }
             else if (butSave.Text == "Update")
             {
                 connection_sql obj = new connection_sql();
                 obj.MakeConnection();

                 string qry = " Update tbl_Courses set " +
                    " Name = '" + txtName.Text + "'" +
                    ", PageTitle = '" + txtPageTitle.Text + "'" +
                    ", Heading = '" + txtHeading.Text + "'" +
                    ", contant = '" + txtFullContents.Text + "'" +
                    ", ShortContent = '" + txtShortContent.Text + "'" +
                    ", status = '" + lblUpdate.Text + "' " +
                    ", urlName ='" + txtMenuURL.Text.Trim() + "'" +
                    ", MenuList = '" + cmbMenuList.Text + "'" +
                    " where id = " + ViewState["UpdateID"].ToString();

                 SqlCommand cmd = new SqlCommand(qry, obj.conn);
                 cmd.ExecuteNonQuery();
                 obj.CloseConnection();
                 ShowNewsDetails();
                 butSave.Text = "Save";
                 btnMainImageFileUpload_Click(sender, e);
                 
                 //txtName.Text = "Name";
                 //txtPageTitle.Text = "PageTitle";
                 //txtHeading.Text = "Heading";
                 //txtFullContents.Text = "FullContents";
                 //txtShortContent.Text = "ShortContent";  
               
                 ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Update Successfully');", true);

             }

        }



        // 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, PageTitle, Heading, contant,ShortContent, Status
                FROM [tbl_Courses] order by id ");
        }

        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, PageTitle, Heading, contant,ShortContent, Status
                FROM [tbl_Courses] order by id desc");

            GridView.DataSource = dt;
            GridView.DataBind();
            obj.CloseConnection();
        }

        protected void btnUploadInContents_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
                string FilePath = "../img/Gallery/Amenties/" + FileName;
                FileUpload1.SaveAs(Server.MapPath(FilePath));
                txtFullContents.Text += string.Format("<img src = '{0}' alt = '{1}' />", FilePath, FileName);
            }
        }

        protected void btnMainImageFileUpload_Click(object sender, EventArgs e)
        {
            if (fuMainImageFileSelect.HasFile)
            {
                string FileName = System.IO.Path.GetFileName(fuMainImageFileSelect.PostedFile.FileName);
                ImagePath = "../img/Courses/" + txtMenuURL.Text.Replace(":", "-").Replace("&", "-").Replace(" ", "-").Replace("/", "-") + ".png";
                fuMainImageFileSelect.SaveAs(Server.MapPath(ImagePath));
                imgMainImage.ImageUrl = ImagePath;
                connection_sql obj = new connection_sql();
                obj.MakeConnection();
                string qry = "";
                int n = 0;
                qry = " Update tbl_Courses set ImagePath='" + ImagePath + "'"
                    + " where name ='" + txtName.Text + "'";
                lblMainImagePath.Text = ImagePath;
                n = obj.ExcuteCommand(qry);
                obj.CloseConnection();

                if (n == 1)
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Save successfully');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Error: not saved');", true);
                }
            }
        }        

        protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Dlt")
            {
                connection_sql obj = new connection_sql();
                obj.MakeConnection();
                SqlCommand cmd = new SqlCommand("DELETE FROM tbl_Courses WHERE ID='" + e.CommandArgument + "' ", obj.conn);
                cmd.ExecuteNonQuery();
                obj.CloseConnection();
                ShowNewsDetails();
                ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Delete Successfully');", true);


            }
            else if (e.CommandName == "Edt")
            {
                connection_sql obj = new connection_sql();
                obj.MakeConnection();
                SqlCommand cmd = new SqlCommand("Select * FROM tbl_Courses WHERE ID='" + e.CommandArgument + "' ", obj.conn);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                obj.CloseConnection();
                butSave.Text = "Update";
                ViewState["UpdateID"] = e.CommandArgument;
                txtName.Text = dt.Rows[0]["name"].ToString();
                txtPageTitle.Text = dt.Rows[0]["name"].ToString();
                txtHeading.Text = dt.Rows[0]["Heading"].ToString();
                txtFullContents.Text = dt.Rows[0]["contant"].ToString();
                txtShortContent.Text = dt.Rows[0]["ShortContent"].ToString();
                txtMenuURL.Text = dt.Rows[0]["URLName"].ToString();
                cmbMenuList.Text = dt.Rows[0]["MenuList"].ToString();
                imgMainImage.ImageUrl = dt.Rows[0]["ImagePath"].ToString();


                lblUpdate.Text= dt.Rows[0]["Status"].ToString();             

            }
        }

        //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("txtName2");
        //        string Text = DataBinder.Eval(e.Row.DataItem, "Name").ToString();
        //        txtName.Text = Text;
        //    }


        //    if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
        //    {
        //        TextBox txtPageTitle = (TextBox)e.Row.FindControl("txtPageTitle2");
        //        string Text = DataBinder.Eval(e.Row.DataItem, "PageTitle").ToString();
        //        txtPageTitle.Text = Text;
        //    }

        //    if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
        //    {
        //        TextBox txtHeading = (TextBox)e.Row.FindControl("txtHeading2");
        //        string Text = DataBinder.Eval(e.Row.DataItem, "Heading").ToString();
        //        txtHeading.Text = Text;
        //    }


        //    if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
        //    {
        //        TextBox txtcontant = (TextBox)e.Row.FindControl("txtcontant2");
        //        string Text = DataBinder.Eval(e.Row.DataItem, "contant").ToString();
        //        txtcontant.Text = Text;
        //    }

        //    if (e.Row.RowType == DataControlRowType.DataRow && GridView.EditIndex == e.Row.RowIndex)
        //    {
        //        TextBox txtShortContent = (TextBox)e.Row.FindControl("txtShortContent2");
        //        string Text = DataBinder.Eval(e.Row.DataItem, "ShortContent").ToString();
        //        txtShortContent.Text = Text;
        //    } 

        //}

        //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 PageTitle = (GridView.Rows[e.RowIndex].FindControl("txtPageTitle2") as TextBox).Text;
        //    string Heading = (GridView.Rows[e.RowIndex].FindControl("txtHeading2") as TextBox).Text;
        //    string content = (GridView.Rows[e.RowIndex].FindControl("txtcontent2") as TextBox).Text;
        //    string ShortContent = (GridView.Rows[e.RowIndex].FindControl("txtShortContent2") 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_Courses SET Status = '" + Status + "', Name ='" + Name + "'"
        //            + " WHERE ID = " + _ID);
        //        lblUpdate.Text = "Record updated successfully.";
        //        Response.Redirect(Request.Url.AbsoluteUri);
        //    }
        //    else
        //    {
        //        obj.ExcuteCommand("delete tbl_Courses 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