public partial class CompanyAdmin_Products : System.Web.UI.Page
{
DAL Obj = new DAL();
protected void Page_Load(object sender, EventArgs e)
{
if(!(IsPostBack ))
{
Obj.Fillgrid(GridView1, "Select PK_ID,Title From Products");
}
if (ViewState["PK_ID"] != null)
{
btn_edit.Visible = true;
btn_save.Visible = false;
}
else
{
btn_save.Visible = true;
btn_edit.Visible = false;
}
}
protected void btn_save_Click(object sender, EventArgs e)
{
string image = "";
if (fileimage.HasFile)
{
FileInfo fi = new FileInfo(fileimage.FileName);
image = Guid.NewGuid().ToString()+ fi .Extension ;
fileimage .SaveAs(Server .MapPath ("~/Productsimage/")+ image);
}
string str = "Products_sp 'I','','" + txttitle.Text + "','" + txt_contents.Value.Replace("'", "''") + "','" + image + "'";
Obj.insrtfun(str);
Obj.Fillgrid(GridView1, "Select PK_ID,Title From Products");
Page.RegisterClientScriptBlock ("V$#WE","<script>alter('Products successfully Added !'),</script>");
ControlClear();
}
protected void btn_edit_Click(object sender, EventArgs e)
{
string image = "";
if (fileimage.HasFile)
{
FileInfo fi = new FileInfo(fileimage.FileName);
image = Guid.NewGuid().ToString() + fi.Extension;
fileimage.SaveAs(Server.MapPath("~/Productsimage/") + image);
//string str = "Products_sp 'U','" + txttitle.Text + "','" + txt_contents.Value.Replace("'", "''") + "','" + image + "' where PK_ID='" + ViewState["PK_ID"] + "'";
//Obj.updatefun(str);
Obj.getdata("Update Products set Title='" + txttitle.Text + "',Productsdetails='" + txt_contents.Value.Replace ("'", "''") + "',Image='" + image + "' where PK_ID ='" + ViewState["PK_ID"]+ "'");
}
else
{
Obj.getdata("Update Products set Title='" + txttitle.Text + "',Productsdetails='" + txt_contents.Value.Replace("'", "''") + "' where PK_ID ='" + ViewState["PK_ID"] + "'");
//string str = "Products_sp 'U','" + txttitle.Text + "','" + txt_contents.Value.Replace("'", "''") + "' where PK_ID='" + ViewState["PK_ID"] + "'";
//Obj.updatefun(str);
}
Obj.Fillgrid(GridView1, "select PK_ID,Title From Products");
ControlClear();
}
private void ControlClear()
{
txttitle.Text = string.Empty;
txt_contents.Value = string.Empty;
ViewState["PK_ID"] = null;
}
protected void btn_cancel_Click(object sender, EventArgs e)
{
ControlClear();
}
protected void btn_grd_edit_click(object sender, CommandEventArgs e)
{
ViewState["PK_ID"] = e.CommandArgument.ToString();
DataTable dt = new DataTable();
dt = Obj.getdata("Select * from Products where PK_ID='" + ViewState["PK_ID"].ToString() + "'");
txttitle.Text = dt.Rows[0]["Title"].ToString();
txt_contents.Value = dt.Rows[0]["Productsdetails"].ToString();
btn_edit.Visible = true;
btn_save.Visible = false;
}
protected void btn_grd_delete_click(object sender, CommandEventArgs e)
{
Obj.getdata("Delete from Products where PK_ID='" + e.CommandArgument.ToString() + "'");
Page.RegisterStartupScript("asas", "<script type='text/javascript'> alert('Record successfully Deleted !');</script>");
Obj.Fillgrid(GridView1, "select PK_ID,Title From Products");
}
}
{
DAL Obj = new DAL();
protected void Page_Load(object sender, EventArgs e)
{
if(!(IsPostBack ))
{
Obj.Fillgrid(GridView1, "Select PK_ID,Title From Products");
}
if (ViewState["PK_ID"] != null)
{
btn_edit.Visible = true;
btn_save.Visible = false;
}
else
{
btn_save.Visible = true;
btn_edit.Visible = false;
}
}
protected void btn_save_Click(object sender, EventArgs e)
{
string image = "";
if (fileimage.HasFile)
{
FileInfo fi = new FileInfo(fileimage.FileName);
image = Guid.NewGuid().ToString()+ fi .Extension ;
fileimage .SaveAs(Server .MapPath ("~/Productsimage/")+ image);
}
string str = "Products_sp 'I','','" + txttitle.Text + "','" + txt_contents.Value.Replace("'", "''") + "','" + image + "'";
Obj.insrtfun(str);
Obj.Fillgrid(GridView1, "Select PK_ID,Title From Products");
Page.RegisterClientScriptBlock ("V$#WE","<script>alter('Products successfully Added !'),</script>");
ControlClear();
}
protected void btn_edit_Click(object sender, EventArgs e)
{
string image = "";
if (fileimage.HasFile)
{
FileInfo fi = new FileInfo(fileimage.FileName);
image = Guid.NewGuid().ToString() + fi.Extension;
fileimage.SaveAs(Server.MapPath("~/Productsimage/") + image);
//string str = "Products_sp 'U','" + txttitle.Text + "','" + txt_contents.Value.Replace("'", "''") + "','" + image + "' where PK_ID='" + ViewState["PK_ID"] + "'";
//Obj.updatefun(str);
Obj.getdata("Update Products set Title='" + txttitle.Text + "',Productsdetails='" + txt_contents.Value.Replace ("'", "''") + "',Image='" + image + "' where PK_ID ='" + ViewState["PK_ID"]+ "'");
}
else
{
Obj.getdata("Update Products set Title='" + txttitle.Text + "',Productsdetails='" + txt_contents.Value.Replace("'", "''") + "' where PK_ID ='" + ViewState["PK_ID"] + "'");
//string str = "Products_sp 'U','" + txttitle.Text + "','" + txt_contents.Value.Replace("'", "''") + "' where PK_ID='" + ViewState["PK_ID"] + "'";
//Obj.updatefun(str);
}
Obj.Fillgrid(GridView1, "select PK_ID,Title From Products");
ControlClear();
}
private void ControlClear()
{
txttitle.Text = string.Empty;
txt_contents.Value = string.Empty;
ViewState["PK_ID"] = null;
}
protected void btn_cancel_Click(object sender, EventArgs e)
{
ControlClear();
}
protected void btn_grd_edit_click(object sender, CommandEventArgs e)
{
ViewState["PK_ID"] = e.CommandArgument.ToString();
DataTable dt = new DataTable();
dt = Obj.getdata("Select * from Products where PK_ID='" + ViewState["PK_ID"].ToString() + "'");
txttitle.Text = dt.Rows[0]["Title"].ToString();
txt_contents.Value = dt.Rows[0]["Productsdetails"].ToString();
btn_edit.Visible = true;
btn_save.Visible = false;
}
protected void btn_grd_delete_click(object sender, CommandEventArgs e)
{
Obj.getdata("Delete from Products where PK_ID='" + e.CommandArgument.ToString() + "'");
Page.RegisterStartupScript("asas", "<script type='text/javascript'> alert('Record successfully Deleted !');</script>");
Obj.Fillgrid(GridView1, "select PK_ID,Title From Products");
}
}
No comments:
Post a Comment