using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using BussinessLogicLayer;
using PropertyLayer;
namespace Prestashop
{
public partial class ManageCategory : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
gvCategoryBind();
}
else
{
DataTable dtCategory = (DataTable)ViewState["dtCategory"];
}
}
protected void gvCategoryBind()
{
BLL objGetCategoryData = new BLL();
DataTable dtCategory = new DataTable();
dtCategory = objGetCategoryData.GetCategoryData();
ViewState["dtCategory"] = dtCategory;
// DataTable dtCategory = (DataTable)ViewState["dtCategory"];
gvCategory.DataSource = dtCategory;
gvCategory.DataBind();
}
protected void btnadd_Click(object sender, EventArgs e)
{
try
{
string filename = Path.GetFileName(fuploadcategory.PostedFile.FileName);
fuploadcategory.SaveAs(Request.PhysicalApplicationPath + "Images/"+txtcategoryname.Text+".jpg");
PL objAddCategoryPL = new PL();
objAddCategoryPL.CategoryName = txtcategoryname.Text;
objAddCategoryPL.ImageName = "Images/" + txtcategoryname.Text+".jpg";
BLL objGetCategoryDetails = new BLL();
int check;
check = objGetCategoryDetails.AddCategoryDetails(objAddCategoryPL);
if (check == 0)
{
Response.Write("Category Not Added");
}
else
{
Response.Redirect("ManageCategory.aspx");
Response.Write("Category Added");
}
}
catch (Exception ee)
{ }
}
protected void gvCategory_RowEditing(object sender, GridViewEditEventArgs e)
{
gvCategory.EditIndex = e.NewEditIndex;
gvCategoryBind();
}
protected void gvCategory_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
PL objCategoryDetails = new PL();
objCategoryDetails.Id = gvCategory.Rows[e.RowIndex].Cells[0].Text;
objCategoryDetails.CategoryName = ((TextBox)gvCategory.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
objCategoryDetails.ImageName = "Images/" + objCategoryDetails.CategoryName + ".jpg";
((FileUpload)gvCategory.Rows[e.RowIndex].FindControl("fuploadEditGv")).SaveAs(Request.PhysicalApplicationPath + "Images/" + objCategoryDetails.CategoryName + ".jpg");
BLL objUpdateCategoryDetails = new BLL();
objUpdateCategoryDetails.UpdateCategoryDetails(objCategoryDetails);
gvCategory.EditIndex = -1;
gvCategoryBind();
Response.Redirect("ManageCategory.aspx");
}
protected void gvCategory_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvCategory.EditIndex = -1;
gvCategoryBind();
}
protected void btncancle_Click(object sender, EventArgs e)
{
txtcategoryname.Text = "";
}
protected void gvCategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
PL objDeleteCategoryDetailsPL = new PL();
objDeleteCategoryDetailsPL.Id = gvCategory.Rows[e.RowIndex].Cells[0].Text;
BLL objDeleteCategoryDetails = new BLL();
objDeleteCategoryDetails.DeleteCategoryDetails(objDeleteCategoryDetailsPL);
gvCategoryBind();
Response.Redirect("ManageCategory.aspx");
}
protected void gvCategory_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvCategory.PageIndex = e.NewPageIndex;
gvCategoryBind();
}
}
}