using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using BusinessLogicLayer;
public partial class Admin_EditItem : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int PID = Convert.ToInt32(Request.QueryString["ID"]);
Session["Pid"] = PID;
fillProductInfo();
}
}
protected void btn_add_Click(object sender, EventArgs e)
{
productBLL objproductBLL = new productBLL();
objproductBLL.Product_Id = 0;
objproductBLL.ProductName = txt_Pname.Text;
objproductBLL.Category_Id = Convert.ToInt32(ddl_catg.SelectedValue);
objproductBLL.Sales_Price = Convert.ToSingle(txt_price.Text.Trim());
objproductBLL.Description = txt_desc.Text;
if (FileUpload1.HasFile)
{
if (CheckExtension(FileUpload1.FileName))
{
if (FileUpload1.PostedFile.ContentLength < 1000000000)
{
string Path = Server.MapPath("~/images/");
Path = Path + "//" + FileUpload1.FileName;
FileUpload1.SaveAs(Path);
}
else
{
}
}
}
else
{
}
objproductBLL.ProductImage = "~/images/" + FileUpload1.FileName;
if (objproductBLL.insertupdateproduct() > 0)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "PremierStore", "alert('Update Successful')", true);
}
{
Label1.Text = "Data Has Been entered Successfully!!!!!!";
}
}
private bool CheckExtension(string fileName)
{
string extension = Path.GetExtension(fileName);
switch (extension.ToLower())
{
case ".jpg": return true;
case ".jpeg": return true;
case ".png": return true;
case ".gif": return true;
default: return false;
}
}
private void fillProductInfo()
{
productBLL objProductBLL = new productBLL();
objProductBLL.Product_Id = Convert.ToInt32(Session["Pid"].ToString());
DataSet ds = new DataSet();
ds = objProductBLL.SelectProduct();
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
txt_Pname.Text = ds.Tables[0].Rows[0]["productName"].ToString();
txt_desc.Text = ds.Tables[0].Rows[0]["description"].ToString();
txt_price.Text = ds.Tables[0].Rows[0]["sales_Price"].ToString();
Image1.ImageUrl = ds.Tables[0].Rows[0]["productImage"].ToString();
ddl_catg.SelectedIndex = ddl_catg.Items.IndexOf(ddl_catg.Items.FindByValue(ds.Tables[0].Rows[0]["category_Id"].ToString()));
}
}
protected void clear()
{
txt_Pname.Text = "";
txt_price.Text = "";
txt_desc.Text = "";
}
}